Exemplo n.º 1
0
	def smooth_resize(img, n_rows, n_cols, smooth_type):
		##----CAUTION---
		## THIS FUNCTION DOES NOT UPSCALE ON ONE AXIS AND DOWNSCALE IN THE OTHER
		# smooth_type= gaussian, bilinear interpolation, median or whatever
		# flag: 0 down else up
		if n_rows==img.shape[0]:
			return img
		if n_cols==img.shape[1]:
			return img
		flag = n_rows > img.shape[0]
		ratio_rows = (n_rows)*1.0 / img.shape[0]
		ratio_cols = (n_cols)*1.0 / img.shape[1]

		if flag:
			kernel_size = (math.ceil((ratio_rows + ratio_cols) / 2))*2-1 
		else:
			kernel_size = (math.ceil(math.log(math.ceil((math.pow(ratio_rows,-1) + math.pow(ratio_cols,-1)) / 2),2)))* 2 + 1
		resized_img = Sampling.simple_resize(img, n_rows, n_cols) if flag else Sampling.simple_resize(img, n_rows, n_cols)

		if smooth_type == Sampling.FILTER_MEDIAN:
			return conv.median_filter_nd(resized_img, kernel_size)
		elif smooth_type == Sampling.FILTER_BILINEAR_INTERPOLATION:
			return conv.convolution_nd(resized_img, ker.bilinear_interpolation(kernel_size))
		elif smooth_type == Sampling.FILTER_GAUSSIAN:
			return conv.convolution_nd(resized_img, ker.gaussian(kernel_size))