ellekaie
ellekaie

Reputation: 337

MATLAB Grayscale showing RGB output

I'm using these lines of code to convert an RGB image to grayscale.

% ===========================
% GRAYSCALE IMAGE
% ===========================
% --- Executes on button press in btnGrayscale.
function btnGrayscale_Callback(hObject, eventdata, handles)
global origImage;    
imageGray = rgb2gray(origImage);
axes(handles.axesEdited);
image(imageGray);

The output doesn't show a grayscale image though.

enter image description here

What seems to be the problem? I'm running MATLAB 6.5 on Windows 7, by the way.

Upvotes: 0

Views: 503

Answers (3)

CyberMan
CyberMan

Reputation: 63

Another way can call one band to show the gray image

imshow(rgb(:,:,2));

Upvotes: 0

ellekaie
ellekaie

Reputation: 337

Thank you for the answers! I thought the problem's with my graphics driver (lol), but when I've tried showing the output on a figure (not on the axis), I found the problem.

Here's a simple solution I've found.

Instead of using image(imageGray);, I've used imshow(imageGray);.

enter image description here

Upvotes: 1

kkuilla
kkuilla

Reputation: 2256

Try this

imshow(imageGray,[])

From imshow:

imshow(I,[]) displays the grayscale image I, where [] is an empty matrix that specifies that you want imshow to scale the image based on the range of pixel values in I, using [min(I(:)) max(I(:))] as the display range.

Upvotes: 1

Related Questions