Skip to content

Instantly share code, notes, and snippets.

@MayeulC
Last active November 3, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MayeulC/626bafbaf925fb3a3c80fdba76b7e8be to your computer and use it in GitHub Desktop.
Save MayeulC/626bafbaf925fb3a3c80fdba76b7e8be to your computer and use it in GitHub Desktop.
Combine two images in the ycbcr (YUV) space.
% This is an Octave script that aims to easily and radically improve
% the sharpness of images from https://github.com/jantic/DeOldify
% for now, it is hand-tuned for one of the sample images
% Script output: https://imgur.com/a/n2sBYCi
pkg load image % pkg install -forge image to install
yoff = 7; % Y offset between the two images, hand-tuned to 6 or 7
im = imread('Ballerinas.jpg');
original = im(yoff+1:end,2:502,:); % should be 2:506
restored = im(1:end-yoff,611:end,:);
figure(1);imshow(original);
figure(2);imshow(restored);
% Take the yuv transform of both images,
% then combine the Y of the grayscale with the UV
% of the colorized one
o_yuv = rgb2ycbcr(original);
r_yuv = rgb2ycbcr(restored);
c_yuv = o_yuv;
c_yuv(:, :, 2:3) = r_yuv(:, :, 2:3);
combined = ycbcr2rgb(c_yuv);
figure(3);imshow(combined);
imwrite(original, 'original.png')
imwrite(restored, 'restored.png')
imwrite(combined, 'combined.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment