Skip to content

Commit

Permalink
Fix image color when labeling with epipolar lines (DeepLabCut#1479)
Browse files Browse the repository at this point in the history
* use cv2.cvtColor to convert BRG2RGB during labeling - fix behavior when using epipolar lines
  • Loading branch information
daltondm authored Aug 26, 2021
1 parent d164d39 commit 51481f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 2 additions & 4 deletions deeplabcut/gui/labeling_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def retrieveData_and_computeEpLines(self, img, imNum):
return None, None, None

def drawEpLines(self, drawImage, lines, sourcePts, offsets, colorIndex, cmap):
drawImage = cv2.cvtColor(drawImage, cv2.COLOR_BGR2RGB)
height, width, depth = drawImage.shape
labelNum = 0
for line, pt, cIdx in zip(lines, sourcePts, colorIndex):
if pt[0] > -1000:
coeffs = line[0]
Expand All @@ -165,13 +163,13 @@ def drawplot(self, img, img_name, itr, index, bodyparts, cmap, keep_view=False):
xlim = self.axes.get_xlim()
ylim = self.axes.get_ylim()
self.axes.clear()

# convert the image to RGB as you are showing the image with matplotlib
im = cv2.imread(img)[..., ::-1]
colorIndex = np.linspace(np.max(im), np.min(im), len(bodyparts))
# draw epipolar lines
epLines, sourcePts, offsets = self.retrieveData_and_computeEpLines(img, itr)
if epLines is not None:
im = self.drawEpLines(im, epLines, sourcePts, offsets, colorIndex, cmap)
im = self.drawEpLines(im.copy(), epLines, sourcePts, offsets, colorIndex, cmap)
ax = self.axes.imshow(im, cmap=cmap)
self.orig_xlim = self.axes.get_xlim()
self.orig_ylim = self.axes.get_ylim()
Expand Down
5 changes: 1 addition & 4 deletions deeplabcut/gui/multiple_individuals_labeling_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def retrieveData_and_computeEpLines(self, img, imNum):
return None, None, None

def drawEpLines(self, drawImage, lines, sourcePts, offsets, colorIndex, cmap):
drawImage = cv2.cvtColor(drawImage, cv2.COLOR_BGR2RGB)
height, width, depth = drawImage.shape
for line, pt, cIdx in zip(lines, sourcePts, colorIndex):
if pt[0] > -1000:
Expand All @@ -168,7 +167,6 @@ def drawplot(self, img, img_name, itr, index, bodyparts, cmap, keep_view=False):
xlim = self.axes.get_xlim()
ylim = self.axes.get_ylim()
self.axes.clear()
# im = cv2.imread(img)
# convert the image to RGB as you are showing the image with matplotlib
im = cv2.imread(img)[..., ::-1]
colorIndex = []
Expand All @@ -178,8 +176,7 @@ def drawplot(self, img, img_name, itr, index, bodyparts, cmap, keep_view=False):
# draw epipolar lines
epLines, sourcePts, offsets = self.retrieveData_and_computeEpLines(img, itr)
if epLines is not None:
im = self.drawEpLines(im, epLines, sourcePts, offsets, colorIndex, cmap)

im = self.drawEpLines(im.copy(), epLines, sourcePts, offsets, colorIndex, cmap)
ax = self.axes.imshow(im, cmap=cmap)
self.orig_xlim = self.axes.get_xlim()
self.orig_ylim = self.axes.get_ylim()
Expand Down

0 comments on commit 51481f6

Please sign in to comment.