コード例 #1
0
ファイル: simple_normalize.py プロジェクト: TienSFU25/earth
def to_channels(filename, normalize):
	img = cv2.imread(filename, 1)
	b, g, r = cv2.split(img)
	total = np.sum(img, axis=2).astype(np.float64)

	r_ = (r.astype(np.float64)/total*255).astype(np.uint8)
	g_ = (g.astype(np.float64)/total*255).astype(np.uint8)
	b_ = (b.astype(np.float64)/total*255).astype(np.uint8)

	if (normalize):
		return r_, g_, b_
	else:
		return r, g, b

def to_cv_image(channels):
	assert len(channels) == 3
	return cv2.merge(channels)

if __name__ == "__main__":
	if len(sys.argv) < 2:
		print 'A filename is required as an argument to run this script'
	else:
		filename = sys.argv[1]
		rgb = to_channels(sys.argv[1], normalize=True)
		img = to_cv_image(rgb)
		cv2.imshow('The normalized image', img)
		cv2.waitKey(0)
		cv2.destroyWindow('The normalized image')

		write_if_yes(img, filename, 'normalized')
コード例 #2
0
ファイル: simple_diff.py プロジェクト: TienSFU25/earth
def to_cv_image(filename):
	img = cv2.imread(filename, 1)
	return img

if __name__ == "__main__":
	if len(sys.argv) < 3:
		print 'Two filenames are required as an argument to run this script'
	else:
		if len(sys.argv) > 3:
			THRESHOLD = int(sys.argv[3])

		file1, file2 = sys.argv[1], sys.argv[2]
		img_1 = to_cv_image(file1)
		img_2 = to_cv_image(file2)

		height = min(img_1.shape[0], img_2.shape[0])
		width = min(img_1.shape[1], img_2.shape[1])
		img_1 = crop(img_1, 0, height, 0, width)
		img_2 = crop(img_2, 0, height, 0, width)
		img = img_1 - img_2

		# pdb.set_trace()
		cv2.imshow('First', img_1)
		cv2.imshow('Second', img_2)
		cv2.imshow('The diff', img)

		cv2.waitKey(0)
		cv2.destroyAllWindows()

		write_if_yes(img, file1, 'diff')