Пример #1
0
 def generateSliceRowMark(self):
     if self.GEN_SLICEROW_MARK:
         demot = self.loadImageRow()
         carver = SeamMarker(img=demot)
         clip = demot[150:250, :]
         clip, mask = carver.mark_row(clip)
         Image.fromarray(clip).save(self.sliceRowMarkPath)
Пример #2
0
 def generateMarkedRowsImage(self):
     if self.GEN_MARK_ROWS:
         demot = self.loadImageRow()
         marker = SeamMarker(demot)
         points = loadJfile(self.points_left_path)
         markedImage = marker.markPointListSeam(img=demot, plist=points)
         Image.fromarray(markedImage).save(self.markRowsImagePath)
Пример #3
0
 def test_seammarker_addPointSlice2Image_colSliceTrue_isUpToFalse(self):
     isUpTo = False
     colSlice = True
     viet = self.loadImageCol()
     points = getPointListFromPointPath(self.points_down_path)
     point = points[0]
     marker = SeamMarker(viet)
     before = 138
     after = 180
     compcolslice = os.path.join(self.imagedir, 'colslice.png')
     compimg = np.array(Image.open(compcolslice))
     compcp = compimg.copy()
     compcphalf = compcp.shape[1] // 2
     compcp[:, compcphalf:compcphalf + 3] = 255
     addedimg = marker.addPointSlice2Image(viet,
                                           point,
                                           beforeAfterCoord=(before, after),
                                           colSlice=colSlice,
                                           imgSlice=compcp,
                                           isUpTo=isUpTo)
     compimg = os.path.join(self.imagedir, 'columnAddedImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(
         addedimg, compimg,
         "Added column does not give the expected added image")
Пример #4
0
 def generateMarkedColumnsImage(self):
     if self.GEN_MARK_COLS:
         viet = self.loadImageCol()
         marker = SeamMarker(viet)
         points = loadJfile(self.points_down_path)
         markedImage = marker.markPointListSeam(img=viet, plist=points)
         Image.fromarray(markedImage).save(self.markColumnsImagePath)
Пример #5
0
 def generateBacktrackSliceMatrix(self):
     if self.GEN_SLICE_BACKTRACK_MAT:
         vietcp = self.loadImageCol()
         vietslice = vietcp[:, 550:600]
         carver = SeamMarker(img=vietcp)
         emap = carver.calc_energy(vietslice.copy())
         mat, backtrack = carver.minimum_seam(img=vietslice, emap=emap)
         np.save(self.slicemat_backtrack_path, backtrack)
Пример #6
0
def getCoordPair(coordpath, colSlice: bool):
    "Get coordinate pair from coordpath and image path"
    img = np.zeros((2, 2), dtype=np.uint8)
    marker = SeamMarker(img)
    coords = getCoordsDict(coordpath)
    plist = list(coords.keys())
    pairs = marker.makePairsFromPoints(plist, colSlice=colSlice)
    return pairs[0]
Пример #7
0
 def generateSliceMark(self):
     if self.GEN_SLICE_MARK:
         viet = self.loadImageCol()
         vietcp = viet.copy()
         vietslice = vietcp[:, 550:600]
         carver = SeamMarker(img=vietcp)
         slicp = vietslice.copy()
         imcp, mask = carver.mark_column(slicp)
         Image.fromarray(imcp).save(self.slicemarkPath)
Пример #8
0
 def generateSliceMatrix(self):
     if self.GEN_SLICE_MAT:
         img = self.loadImageCol()
         viet = np.array(img.copy(), dtype=np.uint8)
         vietslice = viet[:, 550:600]
         carver = SeamMarker(img=None)
         emap = carver.calc_energy(viet.copy())
         mat, backtrack = carver.minimum_seam(img=vietslice.copy(),
                                              emap=emap)
         np.save(self.slicemat_path, mat)
Пример #9
0
 def test_seammarker_markPointListSeam_down(self):
     viet = self.loadImageCol()
     marker = SeamMarker(viet)
     points = loadJfile(self.points_down_path)
     markedImage = marker.markPointListSeam(img=viet, plist=points)
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'markedColumnsImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(markedImage, compimg,
                        "Marked image is not equivalent to expected image")
Пример #10
0
 def test_seammarker_markPointListSeam_left(self):
     demot = self.loadImageRow()
     marker = SeamMarker(demot)
     points = loadJfile(self.points_left_path)
     markedImage = marker.markPointListSeam(img=demot, plist=points)
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'markedRowsImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(markedImage, compimg,
                        "Marked image is not equivalent to expected image")
Пример #11
0
 def generateRowSlice(self):
     if self.GEN_ROW_SLICE:
         demot = self.loadImageRow()
         points = getPointListFromPointPath(self.points_left_path)
         point = points[0]
         carver = SeamMarker(demot)
         rowslice = carver.getRowSliceOnPoint(point,
                                              demot.copy(),
                                              isUpTo=True,
                                              thresh=5)[0]
         Image.fromarray(rowslice).save(self.rowslicePath)
Пример #12
0
 def test_seammarkerk_mark_row(self):
     demot = self.loadImageRow()
     compimg = os.path.join(self.imagedir, 'slicerowmark.png')
     compimg = np.array(Image.open(compimg))
     carver = SeamMarker(img=demot)
     clip = demot[150:250, :]
     clip, mask = carver.mark_row(clip)
     # pdb.set_trace()
     self.compareArrays(
         clip, compimg, "Point carver mark row function emap not given, "
         "checking if function produces same marks on same slice")
Пример #13
0
 def generateColSlice(self):
     if self.GEN_COL_SLICE:
         viet = self.loadImageCol()
         points = getPointListFromPointPath(self.points_down_path)
         point = points[0]
         marker = SeamMarker(viet)
         colslice = marker.getColumnSliceOnPoint(point,
                                                 viet,
                                                 thresh=5,
                                                 isUpTo=False)[0]
         Image.fromarray(colslice).save(self.colslicePath)
Пример #14
0
 def test_seammarker_minimum_seam_emap_matrix(self):
     "tests the minimum seam function of pointcarver"
     matrixPath = os.path.join(self.npdir, "vietSliceMatrix.npy")
     compmatrix = np.load(matrixPath)
     vietImcp = self.loadImageCol()
     vietslice = vietImcp[:, 550:600]
     carver = SeamMarker(img=vietImcp)
     emap = carver.calc_energy(vietslice)
     mat, backtrack = carver.minimum_seam(img=vietslice, emap=emap)
     self.compareArrays(
         mat, compmatrix,
         "Point carver minimum seam function emap given, checking matrix")
Пример #15
0
 def generateSegments(self):
     if self.GEN_SEGMENTS:
         img = self.loadImageCol()
         marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
         coords = prepPointCoord(self.coords_down_path)
         segments = marker.segmentImageWithPointListSeamCoordinate(
             image=img, coords=coords)
         paths = self.segmentPaths
         [[
             Image.fromarray(segs[i]).save(paths[i])
             for i in range(len(segs))
         ] for direction, segs in segments.items()]
Пример #16
0
    def test_seammarker_minimum_seam_backtrack(self):
        backtrackPath = os.path.join(self.npdir, 'vietSliceBacktrack.npy')
        compBacktrack = np.load(backtrackPath)

        vietcp = self.loadImageCol()
        vietslice = vietcp[:, 550:600]
        carver = SeamMarker(img=vietcp)
        mat, backtrack = carver.minimum_seam(img=vietslice)
        self.compareArrays(
            backtrack, compBacktrack,
            "Point carver minimum seam function emap not given, "
            "checking backtrack")
Пример #17
0
 def test_seammarker_getRowSliceOnPointIsUpToTrue(self):
     demot = self.loadImageRow()
     points = getPointListFromPointPath(self.points_left_path)
     point = points[0]
     carver = SeamMarker(demot)
     rowslice = carver.getRowSliceOnPoint(point,
                                          demot,
                                          isUpTo=True,
                                          thresh=5)[0]
     compimg = os.path.join(self.imagedir, 'rowslice.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(rowslice, compimg,
                        "rowslice is not the same for sliced image")
Пример #18
0
 def generateSlicedImage(self):
     if self.GEN_SLICE_IMAGE:
         viet = self.loadImageCol()
         m1 = os.path.join(self.npdir,
                           'matchedMarkCoordPair1ColSliceTrueDown.npy')
         m1 = np.load(m1)
         m2 = os.path.join(self.npdir,
                           'matchedMarkCoordPair2ColSliceTrueDown.npy')
         m2 = np.load(m2)
         marker = SeamMarker(viet)
         colSlice = True
         swaped = marker.swapAndSliceMarkCoordPair(m1, m2, viet, colSlice)
         Image.fromarray(swaped).save(self.sliceImagePath)
Пример #19
0
 def test_seammarker_segmentImageWithPointListSeamCoordinate(self):
     img = self.loadImageCol()
     marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
     coords = prepPointCoord(self.coords_down_path)
     segments = marker.segmentImageWithPointListSeamCoordinate(
         image=img, coords=coords)
     compsegs = self.loadSegments()
     message = "Segment {0} failed"
     # pdb.set_trace()
     compvals = [[
         self.compareArrays(segs[i], compsegs[i], message.format(str(i)))
         for i in range(len(segs))
     ] for direction, segs in segments.items()]
Пример #20
0
 def test_seammarker_mark_column(self):
     compimpath = os.path.join(self.imagedir, 'slicemark.png')
     viet = self.loadImageCol()
     sliceImage = np.array(Image.open(compimpath), dtype=np.uint8)
     vietcp = viet.copy()
     vietslice = vietcp[:, 550:600]
     carver = SeamMarker(img=vietcp)
     slicp = vietslice.copy()
     imcp, mask = carver.mark_column(slicp)
     self.compareArrays(
         imcp, sliceImage,
         "Point carver mark column function emap not given, "
         "checking if function produces same marks on same slice")
Пример #21
0
 def test_seammarker_matchMarkCoordPairLength_left_colSliceFalse(self):
     colSlice = False
     isUpTo = True
     pair = getCoordPair(self.coords_left_path, colSlice)
     coords = getCoordsDict(self.coords_left_path)
     point1 = pair[0]
     point2 = pair[1]
     marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
     coord1 = coords[point1]
     coord2 = coords[point2]
     # pdb.set_trace()
     retval1, retval2 = marker.matchMarkCoordPairLength(
         coord1, coord2, colSlice, isUpTo)
     self.assertEqual(retval1[-1][1], retval2[-1][1])
Пример #22
0
 def test_seammarker_getColSliceOnPointIsUpToFalse(self):
     viet = self.loadImageCol()
     points = getPointListFromPointPath(self.points_down_path)
     point = points[0]
     marker = SeamMarker(viet)
     colslice = marker.getColumnSliceOnPoint(point,
                                             viet,
                                             thresh=5,
                                             isUpTo=False)[0]
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'colslice.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(colslice, compimg,
                        "column slice is not the same for sliced image")
Пример #23
0
 def test_seammarker_markPointSeam_left(self):
     demot = self.loadImageRow()
     points = loadJfile(self.points_left_path)
     point = points["2"]
     point_coord = (point['y'], point['x'])
     marker = SeamMarker(demot)
     markedImage = marker.markPointSeam(img=demot,
                                        point=point_coord,
                                        direction=point['direction'],
                                        thresh=point['threshold'])
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'rowMarkedImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(markedImage, compimg,
                        "Marked image is not equivalent to expected image")
Пример #24
0
 def test_seammarker_markPointSeam_down(self):
     viet = self.loadImageCol()
     points = loadJfile(self.points_down_path)
     point = points["0"]
     point_coord = (point['y'], point['x'])
     marker = SeamMarker(viet)
     markedImage = marker.markPointSeam(img=viet.copy(),
                                        point=point_coord,
                                        direction=point['direction'],
                                        thresh=point['threshold'])
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'colMarkedImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(markedImage, compimg,
                        "Marked image is not equivalent to expected image")
Пример #25
0
 def generateMatchCoordinateMatrix(self, colSlice: bool, isUpTo: bool):
     if self.GEN_MATCH_COORD_PAIRS:
         firstPath = self.match_coord_path.format(str(1))
         secondPath = self.match_coord_path.format(str(2))
         coords = getCoordsDict(self.coords_down_path)
         pair = getCoordPair(self.coords_down_path, colSlice)
         p1 = pair[0]
         p2 = pair[1]
         coord1 = coords[p1]
         coord2 = coords[p2]
         marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
         markCoord1, markCoord2 = marker.matchMarkCoordPairLength(
             coord1, coord2, colSlice, isUpTo)
         np.save(firstPath, markCoord1)
         np.save(secondPath, markCoord2)
Пример #26
0
 def generateColMarkedImage(self):
     if self.GEN_COL_MARKED:
         isUpTo = False
         colSlice = True
         viet = self.loadImageCol()
         points = loadJfile(self.points_down_path)
         point = points["0"]
         point_coord = (point['y'], point['x'])
         marker = SeamMarker(viet)
         markedImage = marker.markSeam4Point(viet,
                                             point_coord,
                                             isUpTo,
                                             point['threshold'],
                                             colSlice,
                                             mark_color=[0, 255, 0])
         Image.fromarray(markedImage).save(self.colMarkedImagePath)
Пример #27
0
 def generateRowMarkedImage(self):
     if self.GEN_ROW_MARKED:
         isUpTo = True
         colSlice = False
         demot = self.loadImageRow()
         points = loadJfile(self.points_left_path)
         point = points["2"]
         point_coord = (point['y'], point['x'])
         marker = SeamMarker(demot)
         markedImage = marker.markSeam4Point(demot,
                                             point_coord,
                                             isUpTo,
                                             point['threshold'],
                                             colSlice,
                                             mark_color=[0, 255, 0])
         Image.fromarray(markedImage).save(self.rowMarkedImagePath)
Пример #28
0
 def test_seammarker_calc_energy(self):
     "tests the calc energy function of pointcarver"
     vietEmap = Image.open(self.emap_path)
     vietEmap = ImageOps.grayscale(vietEmap)
     vietImg = self.loadImageCol()
     vietEmap = np.array(vietEmap, dtype=np.uint8)
     #
     vietImcp = vietImg.copy()
     vietEmapcp = vietEmap.copy()
     #
     carver = SeamMarker(img=vietImcp)
     emap = carver.calc_energy(vietImcp)
     emap = np.interp(emap, (emap.min(), emap.max()), (0, 256))
     emap = np.uint8(emap)
     self.compareArrays(emap, vietEmapcp,
                        "Point carver energy calculation function")
Пример #29
0
 def test_seammarker_expandPointCoordinate_colBeforeIsZero(self):
     "Coord after is above ubound"
     viet = self.loadImageCol()
     vietcp = viet.copy()
     carver = SeamMarker(img=vietcp)
     colBefore, colAfter = carver.expandPointCoordinate(80,
                                                        coord=1,
                                                        thresh=5)
     colbef_comp, col_after_comp = 0, 3
     message = "Point column coordinate is expanded to {0} "
     message1 = "minimum column before is normally lower than 0"
     message2 = "maximum column after is not normally"
     self.assertEqual(colBefore, colbef_comp,
                      message.format('left') + message1)
     self.assertEqual(colAfter, col_after_comp,
                      message.format('right') + message2)
Пример #30
0
 def test_seammarker_swapAndSliceMarkCoordPair_down_colSliceTrue(self):
     viet = self.loadImageCol()
     # pdb.set_trace()
     m1 = os.path.join(self.npdir,
                       'matchedMarkCoordPair1ColSliceTrueDown.npy')
     m1 = np.load(m1)
     m2 = os.path.join(self.npdir,
                       'matchedMarkCoordPair2ColSliceTrueDown.npy')
     m2 = np.load(m2)
     marker = SeamMarker(viet)
     colSlice = True
     swaped = marker.swapAndSliceMarkCoordPair(m1, m2, viet, colSlice)
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'slicedImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(compimg, swaped,
                        "Image slicing with mark coordinate has failed")