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 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 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