imagesc problem when displaying a binary matrix
1 view (last 30 days)
Show older comments
I have a GUI to apply some image processing filters to a matrix. After the filtering I want to display the filtered matrix on my GUI. The last section of my code looks like:
%Dilatation
Image = imdilate(Image,D);
%Erosion
Image = imerode(Image,E);
%Set the global variables
handles.Filtered = Image;
%Show the filtered matrix
imagesc(handles.Filtered,'Parent',handles.AxesA);
As you can imagine, the filtered matrix is displayed on my GUI. The problem is: a gray image is displayed altough I know surely that the filtered matrix contains some binary objects (GUI colormap is gray).
In order to test this I modify my code:
%Dilatation
Image = imdilate(Image,D);
%Erosion
Image = imerode(Image,E);
%Set the global variables
handles.Filtered = Image;
%Get the unique elements
Unique = unique(handles.Filtered);
%Show the filtered matrix in another figure
figure, imagesc(handles.Filtered);
%Show the filtered matrix
imagesc(handles.Filtered,'Parent',handles.AxesA);
Then I get something like this:
Anyone has an idea why a gray image displayed on my GUI? Unique elements in handles.Filtering are 0 and 1.
Thanks.
0 Comments
Answers (2)
Image Analyst
on 29 Mar 2015
Use imshow() instead of imagesc(). I never use imagesc(). It's not quite as bad as pcolor() but almost.
2 Comments
Image Analyst
on 29 Mar 2015
That's not a reason. Use
imshow(yourMatrix, []);
and it will work just fine. You can apply a colormap if you want. Also, don't use Image as the name of a variable - it's dangerously close to image, which is the name of a built-in function.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!