SRCNN的数据处理

TensorFlow代码

数据处理:

输入为(344,288)的图片,首先进行归一化处理,然后下采样再上采样,得到输入input_,

def preprocess(path, scale=3):
  """
  Preprocess single image file 
    (1) Read original image as YCbCr format (and grayscale as default)
    (2) Normalize
    (3) Apply image file with bicubic interpolation

  Args:
    path: file path of desired file
    input_: image applied bicubic interpolation (low-resolution)
    label_: image with original resolution (high-resolution)
  """
  image = imread(path, is_grayscale=True)#(344,228)
  label_ = modcrop(image, scale)#(342,228)modcrop得到scale的整数倍

  # Must be normalized
  image = image / 255.
  label_ = label_ / 255.

  input_ = scipy.ndimage.interpolation.zoom(label_, (1./scale), prefilter=False)#(114,76)
  input_ = scipy.ndimage.interpolation.zoom(input_, (scale/1.), prefilter=False)#(342,228)
  return input_, label_

得到子图片

 input_, label_ = preprocess(data[0], config.scale)

    if len(input_.shape) == 3:
      h, w, _ = input_.shape
    else:
      h, w = input_.shape#(342,228)

    # Numbers of sub-images in height and width of image are needed to compute merge operation.
    nx = ny = 0 
    for x in range(0, h-config.image_size+1, config.stride):#(0,310,21)nx=15,ny=10
      nx += 1; ny = 0
      for y in range(0, w-config.image_size+1, config.stride):#(0,196,21)
        ny += 1
        sub_input = input_[x:x+config.image_size, y:y+config.image_size] # [33 x 33]
        sub_label = label_[x+int(padding):x+int(padding)+config.label_size, y+int(padding):y+int(padding)+config.label_size] # [21 x 21]
        
        sub_input = sub_input.reshape([config.image_size, config.image_size, 1])  #(33,33,1)
        sub_label = sub_label.reshape([config.label_size, config.label_size, 1])  #(21,21,1)

        sub_input_sequence.append(sub_input)
        sub_label_sequence.append(sub_label)

  """
  len(sub_input_sequence) : the number of sub_input (33 x 33 x ch) in one image
  (sub_input_sequence[0]).shape : (33, 33, 1)
  """
  # Make list to numpy array. With this transform
  arrdata = np.asarray(sub_input_sequence) # [?, 33, 33, 1]
  arrlabel = np.asarray(sub_label_sequence) # [?, 21, 21, 1]

  make_data(sess, arrdata, arrlabel)

  if not config.is_train:
    return nx, ny        #15,10
    

猜你喜欢

转载自blog.csdn.net/sinat_39372048/article/details/81181667