imagesc problem when displaying a binary matrix
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.
Answers (2)
Image Analyst
on 29 Mar 2015
0 votes
Use imshow() instead of imagesc(). I never use imagesc(). It's not quite as bad as pcolor() but almost.
2 Comments
Can
on 29 Mar 2015
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.
Can
on 29 Mar 2015
Categories
Find more on Image Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!