Quantize image using lloyds algorithm
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I would like to quantize an image using lloyds algorithm in order to calculate the MSE of an image quantized using the lloyds algorithm. I understand that partition are the levels boundaries and codebook returns the values to be assigned to pixels in each partition range. But i do not understand how to implement the two in order to quantize my image. I've posted my code below, thank you in advance for your time and help!
[M,N] = size(Pic);
training_set = double(Pic(:));
training_set = reshape(training_set,N*M,1);
MSELloyd = zeros(1,7);
for s = 7:-1:1
len = 2.^s;
[partition, codebook] = lloyds(training_set, len);
[PicLloyd ,index] = imquantize(Pic,partition,codebook);
PicLloyd = im2uint8(PicLloyd);
MSELloyd(s) = immse(PicLloyd,Pic);
end
figure; plot(MSELloyd); title('MSE of image quantized by Lloyds');
1 comentario
Naushad Varish
el 3 de En. de 2017
Editada: Walter Roberson
el 3 de En. de 2017
for s = 7:-1:1
len = 2.^s;
[partition, codebook] = lloyds(training_set, len);
[PicLloyd ,index] = imquantize(Pic,partition,codebook);
PicLloyd = im2uint8(PicLloyd);
MSELloyd(s) = immse(PicLloyd,Pic);
end
You should remove the for loop and these two lines i.e.
PicLloyd = im2uint8(PicLloyd);
MSELloyd(s) = immse(PicLloyd,Pic); from your code
Respuestas (1)
Naushad Varish
el 3 de En. de 2017
Editada: Walter Roberson
el 3 de En. de 2017
Your correct code is
s = 7:-1:0
len = 2.^s;
[partition, codebook] = lloyds(training_set, len);
[PicLloyd ,index] = imquantize(Pic,partition,codebook);
Figure, imshow(PicLloyd),
max_t=double(max(gray(:)));
% PSNR calculation
squaredErrorImage = (double(gray) - double(PicLloyd)) .^ 2;
mse = sum(sum(squaredErrorImage)) / (M * N);
PSNR = 20 * log10(max_t/ mse)
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!