I'm trying to understand the idea of quantization with images and how to do so properly. So the image I'd like to do is a bmp file. Looking at mathworks I figured that imquantize would be the proper way to do this, and with what I wanted to uniformly quantize the image into certain K levels. So for example I did this:
K4 = multithresh(I1,4);
I1_quant1 = imquantize(I1,K4);
No5 = figure;
image(I1_quant1);
and with 16 levels right after. That seemed to work well. Unfortunately when I tried to do so with 32 and 64 it doesn't work. Looking at the documentation I saw that you can't go further than 20. So I'm trying to figure out where I went wrong there.
I've attempted with using both linspace:
K64 = linspace(0,1,64); K64(1) = [];
I1_quant4 = imquantize(I1,K64);
No8 = figure;
image(K64(I1_quant4));
and with the suggestion on someone, generalizing linspace to help make the levels:
NLevelsA = 32;
Levels = linspace(min(I1(:)), max(I1(:)), NLevelsA + 1);
Levels(1) = [];
I1_quant3 = imquantize(I1,Levels(1));
No7 = figure;
image(K32(I1_quant3));
Yet those don't seem to work, so I'm asking to see what's possibly wrong here?
in
is in the range [0,255] (8-big unsigned), thenin/8
is in the range [0,31]. MATLAB probably returns a uint8 again, so rounding is built in, but in generalround(double(in)/256*K)
would uniformly quantize to K grey levels. – Cris Luengo