예제 #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 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)
예제 #4
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)
예제 #5
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)
예제 #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())
    plist = [{"x": p[1], "y": p[0]} for p in plist]
    pairs = marker.makePairsFromPoints(plist, colSlice=colSlice)
    return pairs[0]
예제 #7
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)
예제 #8
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")
예제 #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 generateInferior2MeanMatrix(self):
     if self.GEN_MEAN_INF_ZONE_MAT:
         vietImcp = self.loadImageCol()
         vietslice = vietImcp[:, 550:600]
         carver = SeamMarker(img=vietImcp)
         emap = carver.calc_energy(vietslice)
         normalized = normalizeImageVals(emap.copy())
         # vietEmap = ImageOps.grayscale(Image.fromarray(emap))
         funcs = SeamFuncsAI()
         zones = funcs.getInferior2MeanZones(normalized)
         np.save(self.mean_inf_zone_mat_path, zones)
예제 #11
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")
예제 #12
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")
예제 #13
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")
예제 #14
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()]
예제 #15
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")
예제 #16
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()]
예제 #17
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)
예제 #18
0
 def test_seammarker_matchMarkCoordPairLength_down_colSliceTrue(self):
     colSlice = True
     isUpTo = False
     pair = getCoordPair(self.coords_down_path, colSlice)
     coords = getCoordsDict(self.coords_down_path)
     point1 = pair[0]
     point2 = pair[1]
     marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
     coord1 = coords[(point1['y'], point1['x'])]
     coord2 = coords[(point2['y'], point2['x'])]
     retval1, retval2 = marker.matchMarkCoordPairLength(
         coord1, coord2, colSlice, isUpTo)
     # pdb.set_trace()
     self.assertEqual(retval1[-1][0], retval2[-1][0])
예제 #19
0
 def test_seammarker_markPointSeam_down(self):
     viet = self.loadImageCol()
     points = loadJfile(self.points_down_path)
     point = points["0"]
     marker = SeamMarker(viet)
     markedImage = marker.markPointSeam(img=viet.copy(),
                                        point=point,
                                        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")
예제 #20
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,
                                        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")
예제 #21
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)
예제 #22
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")
예제 #23
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)
예제 #24
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)
예제 #25
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")
예제 #26
0
 def test_seammarker_markSeam4Point_colSliceTrue_isUpToFalse(self):
     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,
                                         isUpTo,
                                         point['threshold'],
                                         colSlice,
                                         mark_color=[0, 255, 0])
     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")
예제 #27
0
 def test_seammarker_markSeam4Point_colSliceFalse_isUpToTrue(self):
     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,
                                         isUpTo,
                                         point['threshold'],
                                         colSlice,
                                         mark_color=[0, 255, 0])
     # 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")
예제 #28
0
    def test_seammarker_getPointSeamCoordinate_down(self):
        viet = self.loadImageCol()
        points = getPointListFromPointPath(self.points_down_path)
        point = points[0]
        marker = SeamMarker(viet)
        jfile = loadJfile(self.coords_down_path)
        # pdb.set_trace()
        pointData = getCoordWithPoint(self.coords_down_path, point)
        thresh_val = pointData['threshold']
        direction = pointData['direction']
        coords = marker.getPointSeamCoordinate(viet.copy(),
                                               point,
                                               direction=direction,
                                               thresh=thresh_val)
        coords = shapeCoordinate(coords)

        ccoord = np.array(pointData["seamCoordinates"], dtype=np.int)
        # pdb.set_trace()
        self.compareArrays(coords, ccoord,
                           "Computed coordinates are not equal")
예제 #29
0
 def generateRowSlice(self):
     if self.GEN_ROW_SLICE:
         demot = self.loadImageRow()
         points = getPointListFromPointPath(self.points_left_path)
         point = points[0]
         carver = SeamMarker(demot)
         slicer = PointSlicer(point, demot)
         rowslice = slicer.getRowSliceOnPoint(point,
                                              demot.copy(),
                                              isUpTo=True,
                                              thresh=5)[0]
         Image.fromarray(rowslice).save(self.rowslicePath)
예제 #30
0
 def test_seammarker_sliceImageWithMarkCoordPair_down_colSliceTrue(self):
     "test seam marker slice Image with mark coordinate pair"
     viet = self.loadImageCol()
     marker = SeamMarker(img=np.zeros((2, 2), dtype=np.uint8))
     coords = getCoordsDict(self.coords_down_path)
     colSlice = True
     isUpTo = False
     pair = getCoordPair(self.coords_down_path, colSlice)
     p1 = pair[0]
     p2 = pair[1]
     coord1 = coords[(p1['y'], p1['x'])]
     coord2 = coords[(p2['y'], p2['x'])]
     coord1_2d = coord1[:, :2]
     coord2_2d = coord2[:, :2]
     uni1 = np.unique(coord1_2d, axis=0)
     uni2 = np.unique(coord2_2d, axis=0)
     segment = marker.sliceImageWithMarkCoordPair(viet.copy(), uni1, uni2,
                                                  colSlice, isUpTo)
     # pdb.set_trace()
     compimg = os.path.join(self.imagedir, 'slicedImage.png')
     compimg = np.array(Image.open(compimg))
     self.compareArrays(compimg, segment,
                        "Image slicing with mark coordinate has failed")