def resize(src): height, width, _ = src.shape dst = src if height != width: if a.pad: size = max(height, width) # pad to correct ratio oh = (size - height) // 2 ow = (size - width) // 2 dst = im.pad(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) else: # crop to correct ratio size = min(height, width) oh = (height - size) // 2 ow = (width - size) // 2 dst = im.crop(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) assert (dst.shape[0] == dst.shape[1]) size, _, _ = dst.shape if size > a.size: dst = im.downscale(images=dst, size=[a.size, a.size]) elif size < a.size: dst = im.upscale(images=dst, size=[a.size, a.size]) return dst
def blur(src,scale=4): #通过缩小在放大的方式,对Image进行模糊处理;将image_blur和原image通过combine结合后,即可作为训练数据,输入pix2pix训练DCGAN,训练好的DCGAN中的G网络,当输入一个Image_blur后,可以输出一个image_clear; height,width,_ = src.shape height_down = height // scale width_down = width // scale dst = im.downscale(images=src,size=[height_down,width_down]) dst = im.upscale(images=dst,size=[height,width]) return dst
def blur(src, scale=4): height, width, _ = src.shape height_down = height // scale width_down = height // scale dst = im.downscale(image=src, size=[height_down, width_down]) dst = im.upscale(image=dst, size=[height, width]) return dst
def resize(src): height, width, _ = src.shape dst = src if height != width: if a.pad: size = max(height, width) # pad to correct ratio oh = (size - height) // 2 ow = (size - width) // 2 dst = im.pad(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) else: # crop to correct ratio size = min(height, width) oh = (height - size) // 2 ow = (width - size) // 2 dst = im.crop(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) assert(dst.shape[0] == dst.shape[1]) size, _, _ = dst.shape if size > a.size: dst = im.downscale(images=dst, size=[a.size, a.size]) elif size < a.size: dst = im.upscale(images=dst, size=[a.size, a.size]) return dst
def blur(src, scale=4): height, width, _ = src.shape height_down = height // scale width_down = width // scale dst = im.downscale(images=src, size=[height_down, width_down]) dst = im.upscale(images=dst, size=[height, width]) return dst
def resize(src, tfUpscaleInterpolationType): height, width, _ = src.shape dst = src if a.preserve_aspect_ratio: if height != width: if a.pad: size = max(height, width) # pad to correct ratio oh = (size - height) // 2 ow = (size - width) // 2 dst = im.pad(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) else: # crop to correct ratio size = min(height, width) oh = (height - size) // 2 ow = (width - size) // 2 dst = im.crop(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size) assert (dst.shape[0] == dst.shape[1]) size, _, _ = dst.shape if size > a.fm_input_size: dst = im.downscale(images=dst, size=[a.fm_input_size, a.fm_input_size]) elif size < a.fm_input_size: if tfUpscaleInterpolationType == tf.image.ResizeMethod.BICUBIC: dst = im.upscale( images=dst, size=[a.fm_input_size, a.fm_input_size]) elif tfUpscaleInterpolationType == tf.image.ResizeMethod.NEAREST_NEIGHBOR: dst = im.upscaleWithNearestNeighborInterpolation( images=dst, size=[a.fm_input_size, a.fm_input_size]) else: if tfUpscaleInterpolationType == tf.image.ResizeMethod.BICUBIC: dst = im.upscale(images=dst, size=[a.fm_input_size, a.fm_input_size]) elif tfUpscaleInterpolationType == tf.image.ResizeMethod.NEAREST_NEIGHBOR: dst = im.upscaleWithNearestNeighborInterpolation( images=dst, size=[a.fm_input_size, a.fm_input_size]) return dst
def resize(src): height,width,_ =src.shape dst = src if height != width: if a.pad: #如果需要padding,以较长边padding size = max(height,width) oh = (size - height) // 2 ow = (size - width) // 2 dst = im.pad(image = dst,offset_height = oh, offset_width = ow,target_height = size,target_width = size) else: #否则,以较短边修剪image size = min(height,width) oh = (height - size) //2 ow = (width - size) //2 dst = im.crop(image=dst,offset_height=oh,offset_width=ow,target_height=size,target_width=size) assert(dst.shape[0] == dst.shape[1]) size,_,_ = dst.shape if size > a.size:#如果修剪后的image尺寸与a.size不符合,则进行相应的修改 dst = im.downscale(images=dst,size=[a.size,a.size]) elif size < a.size: dst = im.upscale(images=dst,size=[a.size,a.size]) return dst
def downscaleToSize(src, scaleSize): dst = im.downscale(images=src, size=scaleSize) return dst