def test_seammarker_getRowSliceOnPointIsUpToTrue(self): demot = self.loadImageRow() points = getPointListFromPointPath(self.points_left_path) point = points[0] slicer = PointSlicer(point, demot) rowslice = slicer.getRowSliceOnPoint(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")
def test_seammarker_getColSliceOnPointIsUpToFalse(self): viet = self.loadImageCol() points = getPointListFromPointPath(self.points_down_path) point = points[0] slicer = PointSlicer(point, viet) colslice = slicer.getColumnSliceOnPoint(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")
def generateColSlice(self): if self.GEN_COL_SLICE: viet = self.loadImageCol() points = getPointListFromPointPath(self.points_down_path) point = points[0] slicer = PointSlicer(point, viet) colslice = slicer.getColumnSliceOnPoint(point, viet, thresh=5, isUpTo=False)[0] Image.fromarray(colslice).save(self.colslicePath)
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)
def test_seammarker_expandPointCoordinate_colBeforeIsZero(self): "Coord after is above ubound" viet = self.loadImageCol() vietcp = viet.copy() slicer = PointSlicer({"x": 0, "y": 0}, vietcp) colBefore, colAfter = slicer.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)
def test_seammarker_expandPointCoordinate_normal(self): viet = self.loadImageCol() vietcp = viet.copy() col_nb = vietcp.shape[1] points = getPointListFromPointPath(self.points_down_path) point = points[0] slicer = PointSlicer(point, vietcp) pointCol = point['x'] colBefore, colAfter = slicer.expandPointCoordinate(col_nb, coord=pointCol, thresh=5) # colnb_comp = 872 colbef_comp, col_after_comp = 65, 107 # pdb.set_trace() message = "Point column coordinate is expanded to {0} "\ "in an unexpected way" self.assertEqual(colBefore, colbef_comp, message.format('left')) self.assertEqual(colAfter, col_after_comp, message.format('right'))
def generateRowAdded(self): if self.GEN_ROW_ADDED: isUpTo = True demot = self.loadImageRow() points = getPointListFromPointPath(self.points_left_path) point = points[0] slicer = PointSlicer(point, demot) before = 0 after = 62 rowslice = os.path.join(self.imagedir, 'rowslice.png') rowslice = np.array(Image.open(rowslice)) rowslicecp = rowslice.copy() rowslicehalf = rowslicecp.shape[0] // 2 rowslicecp[rowslicehalf:rowslicehalf + 3, :] = 255 addedimg = slicer.addRowSlice2Image(beforeAfterCoord=(before, after), imgSlice=rowslicecp, isUpTo=isUpTo) Image.fromarray(addedimg).save(self.rowAddedImagePath)
def test_seammarker_addRowSlice2ImageIsUpToTrue(self): isUpTo = True demot = self.loadImageRow() points = getPointListFromPointPath(self.points_left_path) point = points[0] slicer = PointSlicer(point, demot) before = 0 after = 62 rowslice = os.path.join(self.imagedir, 'rowslice.png') rowslice = np.array(Image.open(rowslice)) rowslicecp = rowslice.copy() rowslicehalf = rowslicecp.shape[0] // 2 rowslicecp[rowslicehalf:rowslicehalf + 3, :] = 255 addedimg = slicer.addRowSlice2Image(beforeAfterCoord=(before, after), imgSlice=rowslicecp, isUpTo=isUpTo) compimg = os.path.join(self.imagedir, 'rowAddedImage.png') compimg = np.array(Image.open(compimg)) self.compareArrays(addedimg, compimg, "Added row does not give added image")
def generateColumnAdded(self): if self.GEN_COL_ADDED: isUpTo = False viet = self.loadImageCol() points = getPointListFromPointPath(self.points_down_path) point = points[0] slicer = PointSlicer(point, 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 # pdb.set_trace() addedimg = slicer.addColumnSlice2Image(beforeAfterCoord=(before, after), imgSlice=compcp, isUpTo=isUpTo) Image.fromarray(addedimg).save(self.columnAddedImagePath)
def test_seammarker_addPointSlice2Image_colSliceTrue_isUpToFalse(self): isUpTo = False colSlice = True viet = self.loadImageCol() points = getPointListFromPointPath(self.points_down_path) point = points[0] slicer = PointSlicer(point, 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 = slicer.addPointSlice2Image(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")