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

5 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2021-10-20
编辑:Image Analyst 2021-10-20
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 个评论
Nitin Arora
Nitin Arora 2021-10-20
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 2021-10-20
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by