フィルターのクリア

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

7 ビュー (過去 30 日間)
Nitin Arora
Nitin Arora 2021 年 10 月 20 日
コメント済み: Image Analyst 2021 年 10 月 20 日
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 Center および File ExchangeGet 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