How to quantize hsv ?

5 vues (au cours des 30 derniers jours)
Pedro
Pedro le 25 Oct 2012
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

Réponses (1)

Vidhi Agarwal
Vidhi Agarwal le 12 Juin 2025
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!.

Catégories

En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by