How to quantize hsv ?

조회 수: 4 (최근 30일)
Pedro
Pedro 2012년 10월 25일
답변: Vidhi Agarwal 2025년 6월 12일
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