why is the image blurred after rgb to hsi conversion?

조회 수: 6 (최근 30일)
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 9일
편집: DGM 2023년 12월 19일
Hi, Im trying to convert a rgb image to hsi and i found a piece of code that's supposed to do that but the result is always sort of blurred. I tried other codes as well but same results. Here is the code:
A=imread('image\sat2.jpg');
figure,imshow(A);title('RGB Image');
%Represent the RGB image in [0 1] range
I=double(A)/255;
R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);
%Hue
numi=1/2*((R-G)+(R-B));
denom=((R-G).^2+((R-B).*(G-B))).^0.5;
%To avoid divide by zero exception add a small number in the denominator
H=acosd(numi./(denom+0.000001));
%If B>G then H= 360-Theta
H(B>G)=360-H(B>G);
%Normalize to the range [0 1]
H=H/360;
%Saturation
S=1- (3./(sum(I,3)+0.000001)).*min(I,[],3);
%Intensity
I=sum(I,3)./3;
%HSI
HSI=zeros(size(A));
HSI(:,:,1)=H;
HSI(:,:,2)=S;
HSI(:,:,3)=I;
figure,imshow(HSI);title('HSI Image');
figure,imshow(H);title('hue component');

채택된 답변

Stephen23
Stephen23 2016년 3월 9일
편집: Stephen23 2016년 3월 9일
Because you are inputting an HSI image. The imshow documentation clearly states that it works with greyscale, binary, and RGB images: "Input image, specified as a grayscale, RGB, or binary image." or with indexed images: "Indexed image, specified as a 2-D array of real numeric values". I don't see HSI mentioned anywhere on that page. If you provide incorrect inputs it is not specified what imshow will display.
  댓글 수: 4
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 14일
i want to see the hue component of the image but it looks real fuzzy
Image Analyst
Image Analyst 2016년 3월 14일
Do you have a question? Did you do this:
hsvImage = rgb2hsv(rgbImage);
hImage = hsvImage(:, :, 1); % Extract the hue channel.
imshow(hImage, []); % Display it.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2016년 3월 9일
You need to display H, S, and I all separately. It does not make sense to display H as Red, S as Green, and I as Blue. Even I would not know how to interpret that. It's not blurred, it's just nonsense.

DGM
DGM 2023년 12월 19일
편집: DGM 2023년 12월 19일
The part of the question that nobody answered is "why is it blurry?". The answer is simple. You're looking at a JPG. The lossy compression is most destructive to chroma information, so when the only thing you're looking at is chroma information (i.e. H, S, C, Cb, Cr, A, B, etc), the object content will be most notably deteriorated.
Consider the following example. We have a clean image with hard edges in both brightness and color. All three channels still have crisp edges, even in HSV or HSI.
% a clean synthetic image with hard edges in chroma
rgbpict = imread('clean.png');
imshow(rgbpict,'border','tight')
% convert to HSV
hsvpict = rgb2hsv(rgbpict);
% display all HSV channels
imshow(hsvpict(:,:,1),'border','tight')
imshow(hsvpict(:,:,2),'border','tight')
imshow(hsvpict(:,:,3),'border','tight')
If that same image is stored as a JPG, this is what happens. V is slightly degraded, but H and S fare worse.
% the same image written as a 4:2:0 JPG at 75% quality (default)
rgbpict = imread('garbage.jpg');
% convert to HSV
hsvpict = rgb2hsv(rgbpict);
% display all HSV channels
imshow(hsvpict(:,:,1),'border','tight')
imshow(hsvpict(:,:,2),'border','tight')
imshow(hsvpict(:,:,3),'border','tight')
For this demonstration, it suffices to ignore the differences between HSV/HSL and HSI, as this asymmetric damage will be observable in any model which isolates color and brightness information.
That said, you cannot use hsv2rgb() to convert your HSI image back to RGB. You'd have to use the appropriate tool. If we converted our test image to HSI and then converted the HSI to RGB using hsv2rgb(), this would be the result.
While there are no HSI (or HSL) conversion tools in base MATLAB or IPT, there are conversion tools on the File Exchange. The ones I use are here.
There are also others on the File Exchange, though be aware that some are only one-way (RGB->HSI only). Also be aware that Pascal Getreuer's popular Colorspace Transformations has a bug in the HSI path and will give the incorrect results unless you use the .mex version.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by