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!.