RGB to HSV and then quantization of H and S into 72 and 20 bins respectively.

5 vues (au cours des 30 derniers jours)
I have a RGB image that needs to be converted into HSV space. And then need to convert H and S components into 72 and 20 bins respectively.
RGB to HSV part comleted simply by using HSV = rbg2hsv(RGB) command. Can anyone help in 2nd part i.e. to convert H and S components into 72 and 20 bins?

Réponse acceptée

Image Analyst
Image Analyst le 20 Oct 2021
Modifié(e) : Image Analyst le 20 Oct 2021
Try this:
rgbImage = imread('peppers.png');
subplot(2, 2, 1);
imshow(rgbImage);
title('Original RGB Image')
impixelinfo;
% Convert into HSV color space.
hsvImage = rgb2hsv(rgbImage);
hImage = hsvImage(:, :, 1); % Extract only the hue channel.
sImage = hsvImage(:, :, 2); % Extract only the saturation channel.
subplot(2, 2, 2);
imshow(hImage);
title('Original H Image')
impixelinfo;
% Quantize/posterize into 20 bins.
numberOfBins = 72;
edges = linspace(0, 1, numberOfBins+1)
discreteH = discretize(hImage, edges) / numberOfBins;
subplot(2, 2, 3);
imshow(discreteH)
title('Quantized H Image')
impixelinfo;
% Repeat with 20 bins for S channel.
% Quantize/posterize into 20 bins.
numberOfBins = 20;
edges = linspace(0, 1, numberOfBins+1)
discreteS = discretize(sImage, edges) / numberOfBins;
subplot(2, 2, 4);
imshow(discreteS)
title('Quantized S Image')
impixelinfo;
  2 commentaires
Nitin Arora
Nitin Arora le 20 Oct 2021
Thank you, Image Analyst. Its working perfectly. What if next i want to create the histograms of both H and S components after converting into 70 and 20 bins. What will be size of the respective histograms?
Image Analyst
Image Analyst le 20 Oct 2021
If it worked, yoiu can thank me by clicking the "Vote" icon and the "Accept this answer" link.
You can take a histogram of however many bins you want but it probably makes sense to use the number 70 or 20 and you can do that by passing edges into histogram
edgesH = linspace(0, 1, numberOfBins+1)
discreteH = discretize(hImage, edgesH) / numberOfBins;
subplot(2, 2, 3);
imshow(discreteH)
histogram(discreteH, edgesH);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by