Azzera filtri
Azzera filtri

How to convert each HSI channels to 8-bit grayscale images?

8 visualizzazioni (ultimi 30 giorni)
Hi! I've converted an RGB image to its HSI represenation and split the H, S and I components into three channels. How can I convert these three channels to its respective 8-bit grayscale images?
Should i use mat2gray() function?

Risposta accettata

DGM
DGM il 29 Ott 2021
Modificato: DGM il 29 Ott 2021
You could use mat2gray() here, but you don't want to use the default syntax.
Let's back up and explain why you would think you might. MATLAB/IPT does not have any included HSI conversion tools. All the tools that exist are various and have differing conventions than the built-in HSV conversion tools do. While MATLAB's rgb2hsv() returns hues normalized between 0 and 1, most other tools return hues in degrees from 0 to 360. In such a case, the hue channel needs to be normalized. If the S and I channels are not normalized, they would also need to be.
The problem with using mat2gray() is that it unless you specify the limits, it will normalize the image to its extrema. If you have an image containing very few hues, you will end up stretching out the hues such that it then spans all hues.
% create a test image with a narrow range of hues
A = imread('cameraman.tif');
Ac = imread('cmantifgradbg.png');
A = 0.5*A + 0.5*Ac;
imshow(A)
% normalize using mat2gray()
B = rgb2hsi(A);
B(:,:,1) = mat2gray(B(:,:,1)); % normalize
% what does the image look like if it's converted back?
B(:,:,1) = B(:,:,1)*360; % denormalize
C = hsi2rgb(B); % convert
imshow(C)
Obviously, this is a significant alteration.
In order to avoid this, normalize to the standard extent of the channel (i.e. [0 360]). While you can do this using the explicit syntax for mat2gray(), it's not really necessary. A simple division will suffice.
B = rgb2hsi(A); % convert
B(:,:,1) = B(:,:,1)/360; % normalize
B = im2uint8(B); % cast and scale
% split channels if desired
H = B(:,:,1);
S = B(:,:,2);
I = B(:,:,3);
In these examples, I used the HSI conversion tools found here.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by