Example #1
0
	def __init__(self, name, path, k):
		self.name = name								# name of image
		self.path = path								# path of image
		self.array,_ = OrthoImage.load(path)            # numpy array of raster
		self.label = None								# clustering of image
		self.cover = np.zeros(k)						# cover rates of cluster
		self.error = np.zeros(k)						# error rates of cluster
Example #2
0
def readPolygonTIF(polygonTIF, shpfile, down):
	"""
	Returns the x, y coordinates of the pixels as well as the class 
	labels in numpy arrays based off the polygonTIF. polygonTIF will be 
	effectively downsampled in this function, and thus so are x, y, and class.
	"""
	sample = 2**down

	# arrays to be used to find coordinates and type of the pixels
	x = np.zeros(0)
	y = np.zeros(0)
	classes = np.zeros(0)

	# read in the polygonImage
	polyImage,_ = OrthoImage.load(polygonTIF)
	polyImage = GDAL2OpenCV(polyImage)

	# downsample the polTIF
	if down > 0:
		polyImage = pyramid(polyImage, down)

	# dimensions of TIF image
	if len(polyImage.shape) == 3:
		h, w,_ = polyImage.shape
	elif len(polyImage.shape) == 2:
		h, w = polyImage.shape

	# downsampled dimensions of the bounding box of the polygons
	sf = shapefile.Reader(shpfile)
	lx,_ ,_ , uy = sf.bbox
	lx = lx/sample
	uy = uy/sample*-1

	# iterate through the entire polyImage
	for i in xrange(h):
		for j in xrange(w):
			# if the value of the pixel is 255(crop) then add to the arrays
			# as a crop pixel. The condition is adjusting for downsampling.
			if polyImage[i, j] > 1:
				x = np.append(x, j + lx)
				y = np.append(y, i + uy)
				classes = np.append(classes, 1)

			# else if the value of the pixel is 1 (noncrop) then add to arrays
			# as a noncrop pixel
			elif polyImage[i, j] == 1:
				x = np.append(x, j + lx)
				y = np.append(y, i + uy)
				classes = np.append(classes, 2)

	return x, y, classes