Filter löschen
Filter löschen

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

7 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 20 Okt. 2021
Bearbeitet: Image Analyst am 20 Okt. 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 Kommentare
Nitin Arora
Nitin Arora am 20 Okt. 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 am 20 Okt. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by