显示 RGB 输出的 MATLAB 灰度

MATLAB Grayscale showing RGB output

我正在使用这些代码行将 RGB 图像转换为灰度图像。

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

虽然输出不显示灰度图像。

好像是什么问题?顺便说一下,我在 Windows 7 上 运行 MATLAB 6.5。

试试这个

imshow(imageGray,[])

来自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.

感谢您的解答!我认为问题出在我的图形驱动程序上(笑),但是当我尝试在图形(而不是轴)上显示输出时,我发现了问题。

这是我找到的一个简单的解决方案。

我没有使用 image(imageGray);,而是使用了 imshow(imageGray);

另一种方法可以调用一个波段来显示灰度图像

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