1
$\begingroup$

I have tried to magnify a colored image using bicubic method. I did this in two ways; First, I resize R, G, and B parts of it. Second, I transformed RGB to YCbCr color space and then resized Y, Cb, and Cr parts of it. When I use YCbCr color space, final image changes in color but not in whole shape of the image. I could not realize the reason. May you help me?

code:

clear all
clc

A=imread('Sun.jpg');
R=A(:,:,1);
G=A(:,:,2);
B=A(:,:,3);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y  = 0.257.*R + 0.504.*G + 0.098.*B + 16;
Cb = -0.148.*R - 0.291.*G + 0.439.*B + 128;
Cr = 0.439.*R - 0.368.*G - 0.071.*B + 128;

Y1  = imresize(Y, 2, 'bicubic');
Cb1 = imresize(Cb, 2, 'bicubic');
Cr1 = imresize(Cr, 2, 'bicubic');

R1 = 1.164.*(Y1-16) + 1.596.*(Cr1-128);
G1 = 1.164.*(Y1-16) - 0.813.*(Cr1-128) - 0.391.*(Cb1-128);
B1 = 1.164.*(Y1-16) + 2.018.*(Cb1-128); 

A1 = cat(3,R1,G1,B1);

imwrite(A1,'Sun1.jpg');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R2=imresize(R, 2, 'bicubic');
G2=imresize(G, 2, 'bicubic');
B2=imresize(B, 2, 'bicubic');

A2 = cat(3,R2,G2,B2);

imwrite(A2,'Sun2.jpg');

Original image: enter image description here

Resized image(YCbCr color space): enter image description here

$\endgroup$
2
  • $\begingroup$ Eventhough a slight hue shift might be expected during a resizing of RGB or YCbCr images, which due to various reasons such as formula approximation or computational precision, the images you posted shows more drift then is expected, indicating a formula or implementation error. $\endgroup$
    – Fat32
    Commented Oct 30, 2016 at 9:24
  • $\begingroup$ I checked the formulas in several references. The code is very simple. I have used the resize function of MatLab with a specified method(bicubic). Also, I have tested other methods(such as bilinear and nearest); but the result are not different. I don't really know where this problem comes from? $\endgroup$ Commented Oct 30, 2016 at 9:33

1 Answer 1

0
$\begingroup$

I have checked your code and it worked fine in my matab 6.0 implementation with the following lines of of modification:

A=double(imread('Sun.jpg'));  % convert uint8 data to double
...                           % further operations here
A1(A1(:)<0.0) = 0.0;          % check and correct out of range values
A1(A1(:)>255.0) = 255.0;      % check and correct out of range values
imwrite(A1/255.0,'Sun1.jpg'); % while writing the data of class double use [0,1] data range 

According to this, as I said you must deal with numerical issues such as an out of range value.

$\endgroup$
2
  • 1
    $\begingroup$ You are right. The drawback originates of numerical issues. I used rgb2ycbcr() and ycbcr2rgb() functions of MatLab instead of manual transformation and it passed away. Thanks! $\endgroup$ Commented Oct 30, 2016 at 12:46
  • $\begingroup$ That's good to now! Then you may select the answer as accepted and upvote it, so that the question can be concluded. $\endgroup$
    – Fat32
    Commented Oct 30, 2016 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.