Some indices in indexed images made with cmunique are 0, what does that really mean? Isn’t is a bug? I cannot index a colormap with index=0. Documentation is contradictory.
I transform RGB images to indexed images with cmunique. Some of the indices in the indexed image are 0. It is not mentioned in the help for cmunique, but there is a contradictory statement in the help for rgb2ind, bold in the abbreviated citation below:
"[X,map] = rgb2ind(RGB,n) : Indexed image, returned as an m-by-n matrix X of nonnegative integers. If the length of map is less than or equal to 256, then the output image is of class uint8. Otherwise, the output image is of class uint16. n must be less than or equal to 65,536.
The value 0 in the output array X corresponds to the first color in the colormap."
In my case, the length of smallest color map is of the order of ~1500, so uint16 indices are expected. What do I do with elements of X that are 0 (zero), is there a way to prevent this happening?
Here is my relevant code:
% code snippet
Afull=imread(‘myfigure.png’); % myfigure.png is a color image
rectf=[133 56 521 521];
[fig_xrefout,fig_yrefout,Imfig,rectfig] = imcrop(Afull,rectf);
[Imfig_indexed,fig_map] =cmunique(Imfig);
dum=find(Imfig_indexed<=0);
~isempty(dum) % is 1!!!I transform RGB images to indexed images with cmunique. Some of the indices in the indexed image are 0. It is not mentioned in the help for cmunique, but there is a contradictory statement in the help for rgb2ind, bold in the abbreviated citation below:
"[X,map] = rgb2ind(RGB,n) : Indexed image, returned as an m-by-n matrix X of nonnegative integers. If the length of map is less than or equal to 256, then the output image is of class uint8. Otherwise, the output image is of class uint16. n must be less than or equal to 65,536.
The value 0 in the output array X corresponds to the first color in the colormap."
In my case, the length of smallest color map is of the order of ~1500, so uint16 indices are expected. What do I do with elements of X that are 0 (zero), is there a way to prevent this happening?
Here is my relevant code:
% code snippet
Afull=imread(‘myfigure.png’); % myfigure.png is a color image
rectf=[133 56 521 521];
[fig_xrefout,fig_yrefout,Imfig,rectfig] = imcrop(Afull,rectf);
[Imfig_indexed,fig_map] =cmunique(Imfig);
dum=find(Imfig_indexed<=0);
~isempty(dum) % is 1!!! I transform RGB images to indexed images with cmunique. Some of the indices in the indexed image are 0. It is not mentioned in the help for cmunique, but there is a contradictory statement in the help for rgb2ind, bold in the abbreviated citation below:
"[X,map] = rgb2ind(RGB,n) : Indexed image, returned as an m-by-n matrix X of nonnegative integers. If the length of map is less than or equal to 256, then the output image is of class uint8. Otherwise, the output image is of class uint16. n must be less than or equal to 65,536.
The value 0 in the output array X corresponds to the first color in the colormap."
In my case, the length of smallest color map is of the order of ~1500, so uint16 indices are expected. What do I do with elements of X that are 0 (zero), is there a way to prevent this happening?
Here is my relevant code:
% code snippet
Afull=imread(‘myfigure.png’); % myfigure.png is a color image
rectf=[133 56 521 521];
[fig_xrefout,fig_yrefout,Imfig,rectfig] = imcrop(Afull,rectf);
[Imfig_indexed,fig_map] =cmunique(Imfig);
dum=find(Imfig_indexed<=0);
~isempty(dum) % is 1!!! cmunique, value 0, indexed image MATLAB Answers — New Questions