Esempio n. 1
0
def prepare_raw(path):
    # Settings.
    data = []
    color = []
    padding = abs(size_input - size_label) / 2
    stride = 21
    # Read in image and convert to ycrcb color space.
    img = cv.imread(path)
    im = cv.cvtColor(img, cv.COLOR_BGR2YCR_CB)
    img = im2double(im)  # Only use the luminance value.

    # Create groundtruth and baseline image.
    # im_label = modcrop(img)
    # size = im_label.shape
    size = img.shape
    # im_label = scipy.misc.imresize(im_label, [size[0] * 3, size[1] * 3], interp='bicubic')
    img_temp = scipy.misc.imresize(
        img, [size[0] * multiplier, size[1] * multiplier], interp='bicubic')
    color_temp = scipy.misc.imresize(
        im, [size[0] * multiplier, size[1] * multiplier], interp='bicubic')
    # img_temp = scipy.ndimage.interpolation.zoom(img, 3.0, prefilter=False)
    im_label = img_temp[:, :, 0]
    im_color = color_temp[:, :, 1:3]
    h = im_label.shape[0]
    w = im_label.shape[1]

    # Generate subimages.
    for x in range(0, h - size_input, stride):
        for y in range(0, w - size_input, stride):
            subim_input = im_label[x:x + size_input, y:y + size_input]
            subim_color = im_color[int(x + padding):int(x + padding +
                                                        size_label),
                                   int(y + padding):int(y + padding +
                                                        size_label), :]
            # subim_label = im_label[int(x + padding) : int(x + padding + size_label), int(y + padding) : int(y + padding + size_label)]

            subim_input = subim_input.reshape([size_input, size_input, 1])
            subim_color = subim_color.reshape([size_label, size_label, 2])
            # subim_label = subim_label.reshape([size_label, size_label, 1])

            data.append(subim_input)
            color.append(subim_color)
            # label.append(subim_label)

    data = np.array(data)
    color = np.array(color)
    # label = np.array(label)

    # Write to HDF5 file.
    # savepath = os.path.join(os.getcwd(), 'checkpoint/test_raw_image.h5')
    # with h5py.File(savepath, 'w') as hf:
    # 	hf.create_dataset('data', data=data)
    # 	hf.create_dataset('color', data=color)
    # hf.create_dataset('label', data=label)

    return data, color
Esempio n. 2
0
def prepare_data(path):
    # Settings.
    data = []
    label = []
    padding = abs(size_input - size_label) / 2
    stride = 21
    # Read in image and convert to ycrcb color space.
    img = cv.imread(path)
    img = cv.cvtColor(img, cv.COLOR_RGB2YCR_CB)
    img = im2double(img)  # Only use the luminance value.

    # Create groundtruth and baseline image.
    im_label = modcrop(img, scale=multiplier)
    size = im_label.shape
    h = size[0]
    w = size[1]
    im_temp = scipy.misc.imresize(im_label, 1 / multiplier, interp='bicubic')
    im_input = scipy.misc.imresize(im_temp, multiplier * 1.0, interp='bicubic')

    print('im_temp shape:', im_temp.shape)
    print('im_input shape:', im_input.shape)

    # Generate subimages.
    for x in range(0, h - size_input, stride):
        for y in range(0, w - size_input, stride):
            subim_input = im_input[x:x + size_input, y:y + size_input]
            subim_label = im_label[int(x + padding):int(x + padding +
                                                        size_label),
                                   int(y + padding):int(y + padding +
                                                        size_label)]

            subim_input = subim_input.reshape([size_input, size_input, 1])
            subim_label = subim_label.reshape([size_label, size_label, 1])

            data.append(subim_input)
            label.append(subim_label)

    data = np.array(data)
    label = np.array(label)

    # Write to HDF5 file.
    # savepath = os.path.join(os.getcwd(), 'checkpoint/test_image.h5')
    # with h5py.File(savepath, 'w') as hf:
    # 	hf.create_dataset('data', data=data)
    # 	hf.create_dataset('label', data=label)

    return data, label
Esempio n. 3
0
def prepare_raw(path):
	# Settings.
	data = []
	color = []
	# Read in image and convert to ycrcb color space.
	img = cv.imread(path)
	im = cv.cvtColor(img, cv.COLOR_BGR2YCR_CB)
	img = im2double(im) # Only use the luminance value.

	size = img.shape
	img_temp = scipy.misc.imresize(img, [size[0] * multiplier, size[1] * multiplier], interp='bicubic')
	color_temp = scipy.misc.imresize(im, [size[0] * multiplier, size[1] * multiplier], interp='bicubic')
	im_label = img_temp[:, :, 0]
	im_color = color_temp[:, :, 1:3]

	data = np.array(im_label).reshape([1, img.shape[0] * multiplier, img.shape[1] * multiplier, 1])
	color = np.array(im_color)

	return data, color