def blobs_to_lattice(self, tolerance=None, spacing=None, minspace=None, extend=None, auto_center=False):
		if self.__results['blobs'] is None:
			raise RuntimeError('need blobs to create lattice')
		self.configure_lattice(tolerance=tolerance,spacing=spacing,minspace=minspace, extend=extend)

		shape = self.__results['original'].shape
		blobs = self.__results['blobs']
		tolerance = self.lattice_config['tolerance']
		spacing = self.lattice_config['spacing']
		extend = self.lattice_config['extend']
		# make make list of blob coords:
		points = []
		pointdict = {}
		if len(blobs) < 2 and extend !='off':
			self.__update_result('holes', [])
			return
			
		for blob in blobs:
			point = tuple(blob.stats['center'])
			points.append(point)
			pointdict[point] = blob

		if extend == '3x3':
			if auto_center:
				self.logger.info('Use the blob closest to the center as the 3x3 lattice center')
				points = lattice.sortPointsByDistances(points, (shape[0]/2,shape[1]/2))
			best_lattice = lattice.pointsToLattice(points, spacing, tolerance, first_is_center=True)
		else:
			best_lattice = lattice.pointsToLattice(points, spacing, tolerance)

		if best_lattice is None:
			best_lattice = []
			holes = []
		elif extend == 'full':
			best_lattice = best_lattice.raster(shape)
			holes = self.points_to_blobs(best_lattice)
		elif extend == '3x3':
			best_lattice = best_lattice.raster(shape, layers=1)
			holes = self.points_to_blobs(best_lattice)
		else:
			best_lattice = best_lattice.points
			holes = [pointdict[tuple(point)] for point in best_lattice]

		self.__update_result('lattice', best_lattice)
		if best_lattice is None:
			self.__update_result('holes', [])
		else:
			self.__update_result('holes', holes)
	def blobs_to_lattice(self, tolerance=None, spacing=None, minspace=None):
		if self.__results['blobs'] is None:
			raise RuntimeError('need blobs to create lattice')
		self.configure_lattice(tolerance=tolerance,spacing=spacing,minspace=minspace)

		blobs = self.__results['blobs']
		tolerance = self.lattice_config['tolerance']
		spacing = self.lattice_config['spacing']
		# make make list of blob coords:
		points = []
		pointdict = {}
		for blob in blobs:
			point = tuple(blob.stats['center'])
			points.append(point)
			pointdict[point] = blob
		
		best_lattice = lattice.pointsToLattice(points, spacing, tolerance)
		if best_lattice is None:
			best_lattice = []
		else:
			best_lattice = best_lattice.points
		holes = [pointdict[tuple(point)] for point in best_lattice]

		self.__update_result('lattice', best_lattice)
		if best_lattice is None:
			self.__update_result('holes', [])
		else:
			self.__update_result('holes', holes)
Beispiel #3
0
	def _run(self):
		# get deps
		points = self.depresults['input']

		# get params
		tolerance = self.params['tolerance']
		spacing = self.params['spacing']

		# make make list of blob coords:
		testpoints = []
		for point in points:
			testpoint = point['row'], point['column']
			testpoints.append(testpoint)

		best_lattice = lattice.pointsToLattice(testpoints, spacing, tolerance)

		if best_lattice is None:
			best_lattice = []
			holes = []
		else:
			best_lattice = best_lattice.points

		latpoints = [{'row': point[0], 'column': point[1]} for point in best_lattice]

		return latpoints
    def convolve3x3WithBlobPoints(self, points):
        if len(points) < 2:
            self.logger.warning(
                'Need at least 2 point to determine 3x3 patter orientation')
            return []
        shape = self.__results['original'].shape
        tolerance = self.lattice_config['tolerance']
        spacing = self.lattice_config['spacing']
        total_lattice_points = []
        # Use the first two points to get the rotation of the 3x3 holes
        vector = (points[1][0] - points[0][0], points[1][1] - points[0][1])
        vector_length = math.hypot(vector[0], vector[1])
        # scaling the 3x3 pattern to have the spacing of the lattice_config
        scaled_vector = map((lambda x: x * spacing / vector_length), vector)

        def shiftpoint(point, vector):
            return (point[0] + vector[0], point[1] + vector[1])

        for point in points:
            newpoints = [point, shiftpoint(point, scaled_vector)]
            best_lattice = lattice.pointsToLattice(newpoints,
                                                   spacing,
                                                   tolerance,
                                                   first_is_center=True)
            best_lattice_points = best_lattice.raster(shape, layers=1)
            total_lattice_points.extend(best_lattice_points)
        return total_lattice_points
    def _run(self):
        # get deps
        points = self.depresults['input']

        # get params
        tolerance = self.params['tolerance']
        spacing = self.params['spacing']

        # make make list of blob coords:
        testpoints = []
        for point in points:
            testpoint = point['row'], point['column']
            testpoints.append(testpoint)

        best_lattice = lattice.pointsToLattice(testpoints, spacing, tolerance)

        if best_lattice is None:
            best_lattice = []
            holes = []
        else:
            best_lattice = best_lattice.points

        latpoints = [{
            'row': point[0],
            'column': point[1]
        } for point in best_lattice]

        return latpoints
    def blobs_to_lattice(self,
                         tolerance=None,
                         spacing=None,
                         minspace=None,
                         extend=None,
                         auto_center=False):
        if self.__results['blobs'] is None:
            raise RuntimeError('need blobs to create lattice')
        self.configure_lattice(tolerance=tolerance,
                               spacing=spacing,
                               minspace=minspace,
                               extend=extend)

        shape = self.__results['original'].shape
        blobs = self.__results['blobs']
        tolerance = self.lattice_config['tolerance']
        spacing = self.lattice_config['spacing']
        extend = self.lattice_config['extend']
        # make make list of blob coords:
        points = []
        pointdict = {}
        if len(blobs) < 2 and extend != 'off':
            self.__update_result('holes', [])
            return

        for blob in blobs:
            point = tuple(blob.stats['center'])
            points.append(point)
            pointdict[point] = blob

        if extend == '3x3':
            # Not to use points to determine Lattice but continue with extension
            best_lattice = True
        else:
            best_lattice = lattice.pointsToLattice(points, spacing, tolerance)

        if best_lattice is None:
            best_lattice_points = []
            holes = []
        elif extend == 'full':
            best_lattice_points = best_lattice.raster(shape)
            holes = self.points_to_blobs(best_lattice_points)
        elif extend == '3x3':
            best_lattice_points = self.convolve3x3WithBlobPoints(points)
            holes = self.points_to_blobs(best_lattice_points)
        else:
            best_lattice_points = best_lattice.points
            holes = [pointdict[tuple(point)] for point in best_lattice_points]

        self.__update_result('lattice', best_lattice)
        if best_lattice is None:
            self.__update_result('holes', [])
        else:
            self.__update_result('holes', holes)
	def blobs_to_lattice(self, tolerance=None, spacing=None, minspace=None, extend=None, auto_center=False):
		if self.__results['blobs'] is None:
			raise RuntimeError('need blobs to create lattice')
		self.configure_lattice(tolerance=tolerance,spacing=spacing,minspace=minspace, extend=extend)

		shape = self.__results['original'].shape
		blobs = self.__results['blobs']
		tolerance = self.lattice_config['tolerance']
		spacing = self.lattice_config['spacing']
		extend = self.lattice_config['extend']
		# make make list of blob coords:
		points = []
		pointdict = {}
		if len(blobs) < 2 and extend !='off':
			self.__update_result('holes', [])
			return
			
		for blob in blobs:
			point = tuple(blob.stats['center'])
			points.append(point)
			pointdict[point] = blob

		if extend == '3x3':
			# Not to use points to determine Lattice but continue with extension
			best_lattice = True
		else:
			best_lattice = lattice.pointsToLattice(points, spacing, tolerance)

		if best_lattice is None:
			best_lattice_points = []
			holes = []
		elif extend == 'full':
			best_lattice_points = best_lattice.raster(shape)
			best_lattice_points = best_lattice.optimizeRaster(best_lattice_points,best_lattice.points)
			holes = self.points_to_blobs(best_lattice_points)
		elif extend == '3x3':
			best_lattice_points = self.convolve3x3WithBlobPoints(points)
			holes = self.points_to_blobs(best_lattice_points)
		else:
			best_lattice_points = best_lattice.points
			holes = [pointdict[tuple(point)] for point in best_lattice_points]

		self.__update_result('lattice', best_lattice)
		if best_lattice is None:
			self.__update_result('holes', [])
		else:
			self.__update_result('holes', holes)
	def convolve3x3WithBlobPoints(self,points):
		if len(points) < 2:
			self.logger.warning('Need at least 2 point to determine 3x3 patter orientation')
			return []
		shape = self.__results['original'].shape
		tolerance = self.lattice_config['tolerance']
		spacing = self.lattice_config['spacing']
		total_lattice_points = []
		# Use the first two points to get the rotation of the 3x3 holes
		vector = (points[1][0]-points[0][0],points[1][1]-points[0][1])
		vector_length = math.hypot(vector[0],vector[1])
		# scaling the 3x3 pattern to have the spacing of the lattice_config
		scaled_vector = map((lambda x: x*spacing/vector_length),vector)
		def shiftpoint(point,vector):
			return (point[0]+vector[0],point[1]+vector[1])
		for point in points:
			newpoints = [point,shiftpoint(point,scaled_vector)]
			best_lattice = lattice.pointsToLattice(newpoints, spacing, tolerance, first_is_center=True)
			best_lattice_points = best_lattice.raster(shape, layers=1)
			total_lattice_points.extend(best_lattice_points)
		return total_lattice_points