Is there any built in function for rgb to HSI and CMY?

6 visualizaciones (últimos 30 días)
Neha Khan
Neha Khan el 8 de Jul. de 2023
Editada: DGM el 8 de Jul. de 2023
is there any other way to convert hsi and cmy
I = imread('garden.jpg');
% Plotting RGB Image
subplot(3,3,1);
imshow(I);
title('RGB Image');
% Calculating and plotting RGB Histogram
R = imhist(I(:,:,1));
G = imhist(I(:,:,2));
B = imhist(I(:,:,3));
subplot(3,3,2);
plot(R,'r');
hold on;
plot(G,'g');
plot(B,'b');
legend('Red channel','Green channel','Blue channel');
hold off;
% Getting the size of the image in bytes
image_size_bytes = numel(I);
subplot(3,3,3);
text(0.5,0.5,sprintf('Size: %d bytes',
image_size_bytes),'HorizontalAlignment','center','VerticalAlignment','middle'
);
axis off;
title('Image Size');
% Convert RGB to HSI
% Convert RGB image to double precision
I = im2double(I);
% Convert RGB to HSV
HSI = rgb2hsv(I);
% Extract RGB channels
R = I(:, :, 1);
G = I(:, :, 2);
B = I(:, :, 3);
% Extract HSI channels
H = HSI(:, :, 1);
S = HSI(:, :, 2);
I = HSI(:, :, 3);
% Create the combined image
combinedImage = cat(3, H, S, I);
subplot(3,3,4);
imshow(combinedImage);
title('RGB to HSI');
% Calculating and plotting RGB Histogram
RH = imhist(HSI(:,:,1));
GH = imhist(HSI(:,:,2));
BH = imhist(HSI(:,:,3));
subplot(3,3,5);
plot(RH,'r');
hold on;
plot(GH,'g');
plot(BH,'b');
legend('Red channel','Green channel','Blue channel');
hold off;
image_size_bytes = numel(HSI);
subplot(3,3,6);
text(0.5,0.5,sprintf('Size: %d bytes',
image_size_bytes),'HorizontalAlignment','center','VerticalAlignment','middle'
);
axis off;
title('Image Size');
% Convert RGB to CMY
CMY = imcomplement(I);
subplot(3,3,7);
imshow(CMY);
title('CMY Image');
%histogram
RC = imhist(CMY(:,:,1));
GC = imhist(CMY(:,:,2));
BC = imhist(CMY(:,:,3));
subplot(3,3,8);
plot(RC,'r');
hold on;
plot(GC,'g');
plot(BC,'b');
legend('Red channel','Green channel','Blue channel');
hold off;
%size
image_size_bytes = numel(CMY);
subplot(3,3,9);
text(0.5,0.5,sprintf('Size: %d bytes',
image_size_bytes),'HorizontalAlignment','center','VerticalAlignment','middle'
);
axis off;
title('Image Size');

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Jul. de 2023
There is no built-in function that converts directly from rgb to HSI. See https://www.mathworks.com/matlabcentral/fileexchange/53354-colorspace-conversion-tools or similar. See also makecform and applycform -- which is built-in but requires two steps.
  1 comentario
DGM
DGM el 8 de Jul. de 2023
Editada: DGM el 8 de Jul. de 2023
I'll just add that while those MIMT tools do include RGB<->CMYK conversion tools, they're the naive examples used by G'MIC. They exist for equally simpistic purposes. They might be fine depending on your needs, but if you're trying to do print preparation, they're totally unsuitable.
I never created a set of CMY-only conversions, though you could just do what you're doing or modify the CMYK tools.
While there are other HSI tools on the FEX, few offer both conversions. Pascal Getreuer's colorspace() is popular, but it's unmaintained and the m-code version of the HSI conversions has a bug and will not return the correct results.

Iniciar sesión para comentar.

Categorías

Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by