How to quantize hsv ?

6 次查看(过去 30 天)
Pedro
Pedro 2012-10-25
So, i just converted one rgb image to hsv.
Now, i want to quantize this one to get 18 H, 3 S and 3 V.
I'm a beginner in this area. Can someone give me some tips or ideas to do this ?
Thank you all

回答(1 个)

Vidhi Agarwal
Vidhi Agarwal 2025-6-12
Hi @Pedro,
I understand you are trying to quantize an HSV image into 18 H bins, 3 S bins, and 3 V bins using MATLAB. Below steps can help you in getting started:
  • Read and convert RGB to HSV.
  • Quantize each channel. Sample code for the same is given below:
img = imread('your_image.jpg'); % Load image
img_hsv = rgb2hsv(img); % Convert to HSV
H = img_hsv(:,:,1); % Hue in range [0, 1]
S = img_hsv(:,:,2); % Saturation in range [0, 1]
V = img_hsv(:,:,3);
Hq = floor(H * 18); % 18 bins → values from 0 to 17
Sq = floor(S * 3); % 3 bins → values from 0 to 2
Vq = floor(V * 3); % 3 bins → values from 0 to 2
% Handle edge cases where value = 1 (since floor(1*18)=18, not valid)
Hq(Hq == 18) = 17;
Sq(Sq == 3) = 2;
Vq(Vq == 3) = 2;
  • Create a Single Quantized Label Map: By combining the quantized channels into one index (0 to 161).
Hope this helps!.

类别

Help CenterFile Exchange 中查找有关 Image Filtering and Enhancement 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by