def _detectEdges(self, image): edgeDetector = EdgeDetector(rgb2grayNaive(image.image)) edges = edgeDetector.getEdges( self._edgeDetectionConfig.sigma, self._edgeDetectionConfig.thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage( self._edgeDetectionConfig.radius) edges = keepInsideStage.execute(edges) trimmedEdges = self._trimEdges(edges) return _convertToMatrix(trimmedEdges)
def test_RealImage(self): image = rgb2grayNaive(readImage("images_unittest/1.jpg")) e = EdgeDetector(image) cloud = e.getEdges(2.2, 6.5) self.assertEqual(cloud.size(), 300) fewPointsCloud = e.getEdges(2.2, 26.0) self.assertEqual(fewPointsCloud.size(), 2) noPointsCloud = e.getEdges(2.2, 27.0) self.assertEqual(noPointsCloud.size(), 0)
def _drawReferenceImages(self): numPlotsPerSide = int(math.ceil(math.sqrt(len(self._referenceImages)))) print("numPlotsPerSide:", numPlotsPerSide) for ix, reference in enumerate(self._referenceImages): ax = self._referenceImagesFigure.add_subplot( numPlotsPerSide, numPlotsPerSide, ix + 1) edgeDetector = EdgeDetector(rgb2grayNaive(reference.image)) edges = edgeDetector.getEdges(self._sigma, self._thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage(self._radius) edges = keepInsideStage.execute(edges) imageToShow = reference.image.copy() addPointsToImage(imageToShow, edges, 1) ax.imshow(imageToShow) plt.show(block=False)
def _dumpPointsToFile(self): inputDirStr = _userCheckedInput("Image dir path: ") outputDirStr = _userCheckedInput("Output dir path: ") outputPostfixStr = _userCheckedInput("Output postfix str: ") imageReader = DirectoryImageReader(inputDirStr) for image in imageReader.generate(): print(image.comment) edgeDetector = EdgeDetector(rgb2grayNaive(image.image)) cloud = edgeDetector.getEdges(self._sigma, self._thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage(self._radius) cloud = keepInsideStage.execute(cloud) outFilePath = os.path.join(outputDirStr, image.comment + outputPostfixStr) outFile = open(outFilePath, "w") PointCloudHandler.savePointCloudToWriteable(cloud, outFile) outFile.close()
b = 0.583 aDist = (lab[..., 1] + 128.0) / 256.0 - a bDist = (lab[..., 2] + 128.0) / 256.0 - b dist = aDist * aDist + bDist * bDist # super naive filtering done here for experimentation filtered = img1.copy() filtered = filtered / 255.0 filtered[..., 0] *= np.exp(-dist * 200.0) filtered[..., 1] *= np.exp(-dist * 200.0) filtered[..., 2] *= np.exp(-dist * 200.0) xyz = cieLabToCieXyz(lab) rgb = cieXyzToSrgb(xyz) plt.figure() g = rgb2grayNaive(img1) plt.imshow(g, cmap="gray") plt.figure() plt.imshow(rgb2grayNaive(filtered), cmap="gray") plt.figure() plt.imshow((lab + 100.0) / 200.0) plt.figure() plt.imshow(rgb) plt.show()
filePath1 = "../../images/early_tests_white/4_01.jpg" filePath2 = "../../images/early_tests_white/4_03.jpg" start = timer() img1 = imageio.imread(filePath1) img2 = imageio.imread(filePath2) end = timer() print("imread:", end - start) sigma = 2 thresholdFactor = 8.0 radius = 30 start = timer() edgeDetector1 = EdgeDetector(rgb2grayNaive(img1)) edgeDetector2 = EdgeDetector(rgb2grayNaive(img2)) edges1 = edgeDetector1.getEdges(sigma, thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage(radius) edges1 = keepInsideStage.execute(edges1) edges2 = edgeDetector2.getEdges(sigma, thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage(radius) edges2 = keepInsideStage.execute(edges2) end = timer() print("edgedetector:", end - start) points1 = np.zeros((edges1.size(), 2)) for ix, point in enumerate(edges1): points1[ix, 0] = point[0]
from EdgeDetector import EdgeDetector from ImageUtilities import rgb2grayNaive import PipelineStage def addEdgesToImage(image, edges, colorIx): for point in edges: row = point[0] col = point[1] image[int(row), int(col), colorIx] = 255 if __name__ == "__main__": filePath = "../../images/TryEdgeDetector.jpg" img = imageio.imread(filePath) edgeDetector = EdgeDetector(rgb2grayNaive(img)) radius = 1000 sigma = 4 thresholdFactor = 0.4 edges = edgeDetector.getEdges(sigma, thresholdFactor) keepInsideStage = PipelineStage.KeepInsideRadiusStage(radius) edges = keepInsideStage.execute(edges) print("Got", edges.size(), "edge points at sigma", sigma, "and thresholdFactor", thresholdFactor) addEdgesToImage(img, edges, 0) addEdgesToImage(img, edges, 2) sigma = 8 thresholdFactor = 0.1