How to quantize hsv ?

4 visualizaciones (últimos 30 días)
Pedro
Pedro el 25 de Oct. de 2012
Respondida: Vidhi Agarwal el 12 de Jun. de 2025
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

Respuestas (1)

Vidhi Agarwal
Vidhi Agarwal el 12 de Jun. de 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!.

Categorías

Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by