Magnification of a colored image through two color space: RGB & YCbCr

3 次查看(过去 30 天)
Hi all
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 image. I could not able to 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:

回答(2 个)

Image Analyst
Image Analyst 2016-10-29
编辑:Image Analyst 2016-10-29
Check the sizes. imresize() will change the size of the lateral dimensions, however when you use imshow(), imshow() will resize the image to fit the axes on your screen, so it may appear the same size even though it's not.
By the way, there is a rgb2ycbcr() function that you should use instead of doing it manually.

DGM
DGM 2022-12-18
This has nothing to do with imresize(). The problem here is caused entirely by information loss by in intermediate YCbCr conversion calculations. Pay attention to data class and scale. The input image is uint8. YCbCr is (commonly) uint8. That said, what happens when you take integer-class data and do this?
Cr = 0.439.*R - 0.368.*G - 0.071.*B + 128;
Pay attention to the green and blue terms especially. Cr contains zero information from G or B. It only contains information from R. In short, it's garbage.
If you want to perform your calculations in uint8-scale, then use double() to cast the input to floating-point while keeping its scale. When you're done, you can cast the result back using uint8().
If you want to do your calculations in actual uint8, you'll have to learn how to jump through all the hoops necessary to do integer math without losing everything.
As @Image Analyst mentioned, it's a lot easier to use the inbuilt tools to do the conversion instead.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by