why is the image blurred after rgb to hsi conversion?
3 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
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 个评论
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
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.
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!