0

I am using Matlab's GUIDE for the first time, I am trying to edit one of the two push button functions (both open an image), but editing one changes all of them. Here is a bit of code:

% --- Executes on button press in Floating.
function Floating_Callback(hObject, eventdata, handles)

clc;
axes(handles.axes1);
[Float, PathName, FilterIndex] = uigetfile('*.bmp');
if(Float ~= 0) 
    Floating = fullfile(PathName, Float);
    FloatArray = imread(Floating);
    imshow(FloatArray);
    axis on; 
end 

% Update handles structure
guidata(hObject, handles);

% hObject    handle to Floating (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Reference.
function Reference_Callback(hObject, eventdata, handles)

clc;
axes(handles.axes2);
[Ref, PathName, FilterIndex] = uigetfile('*.bmp');
if(Ref ~= 0) 
    Reference = fullfile(PathName, Ref);
    ReferenceArray = imread(Reference);
    image(ReferenceArray); 
end 

% Update handles structure
guidata(hObject, handles);

For example,

image(ReferenceArray) 

will open an image in RBG, but

imshow(FloatArray) 

will open in grayscale (I also do not understand why that is). But my main concern is after opening up

imshow(FloatArray)

the other image will automatically turn grayscale. I am very confused... Also, as far as I know the images ARE already grayscale, at least they are when I open them in MS paint or ImageJ.

Shinobii
  • 2,401
  • 5
  • 24
  • 39
  • read the images in MATLAB (`img = imread('...')`) and post the output of `size(img)` and `class(img)` for both images – Amro Jul 24 '12 at 16:24

1 Answers1

1

It would be better to explicitly specify the parent handle whenever you are doing GUI stuff. For example:

imshow(img, 'Parent',handles.ax1)

and

axis(handles.ax1, 'on')

As for images and colormaps, you should understand the type of images MATLAB supports (indexed vs. truecolor). Also note that a figure has only one colormap applied to all images, although there are techniques to overcome this.

Amro
  • 123,847
  • 25
  • 243
  • 454