Why an error occurs in cmunique with images with colour palettes larger than 256*256 colours?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Maria Jose Luque
el 10 de Feb. de 2017
Comentada: Maria Jose Luque
el 15 de Feb. de 2017
Found an error in cmunique when working with images with large colourmaps.
>> im=rand(256*257,1,3);
>> [Y,newmap] = cmunique(im);
Error using -
Matrix dimensions must agree.
Error in cmunique (line 107)
loc = (1:nmap) - cumsum(d);
The error appears to be caused by line 105 in cmunique
n = histcounts(c,'BinMethod','integers','BinLimits',[1 nmap]);
If nmap<=256*256, all works well, but if nmap>=256*257, the length of n suddenly drops by an order of magnitude (and the number of counts for each color changes from 1 to 10!)
Any reason why this should be so?
2 comentarios
Walter Roberson
el 15 de Feb. de 2017
The code should not be relying on those parameters for histcounts :(
Respuesta aceptada
Walter Roberson
el 15 de Feb. de 2017
Editada: Walter Roberson
el 15 de Feb. de 2017
I suggest
[newmap, ~, uidx] = unique( reshape(im, [], 3), 'rows');
Y = reshape(uidx, size(im, 1), size(im, 2) );
mlen = length(newmap);
if mlen <= 256
Y = uint8(Y - 1);
elseif mlen <= 65536
Y = uint16(Y - 1);
%else leave it as-is
end
Más respuestas (1)
Darshan Ramakant Bhat
el 15 de Feb. de 2017
It seems MATLAB has an issue with this function. I recommend you to use ' rgb2ind ' function instead. Document link for the function is given below:
I hope this will serve your purpose.
Regards
Darshan Bhat
2 comentarios
Walter Roberson
el 15 de Feb. de 2017
rgb2ind is not suitable for this situation. Notice that
"n must be less than or equal to 65,536"
which is 256*256.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!