Thread Subject: Contrast Slider

Subject: Contrast Slider

From: Kris Langheinrich

Date: 19 Apr, 2008 19:28:02

Message: 1 of 3

For a school project i'm trying to create a gui that pulls
up an MRI image and has a slider bar which adjusts the
contrast of the image. I'm able to load the MRI image but
my slider bar doesn't change the contrast. I don't
understand which function to use and how to go about doing
this!!! Any help????

Subject: Contrast Slider

From: Abel Brown

Date: 19 Apr, 2008 19:33:02

Message: 2 of 3

"Kris Langheinrich" <bubs2407@gmail.com> wrote in message
<fudh42$d6$1@fred.mathworks.com>...
> For a school project i'm trying to create a gui that pulls
> up an MRI image and has a slider bar which adjusts the
> contrast of the image. I'm able to load the MRI image but
> my slider bar doesn't change the contrast. I don't
> understand which function to use and how to go about doing
> this!!! Any help????


Can you post your slider callback? That would really help.
 Right now we can only guess at what you're doing ;)

Subject: Contrast Slider

From: Robert Berry

Date: 25 Nov, 2009 16:23:19

Message: 3 of 3

I'm having a problem similar to the user that started this thread. In my GUI, the user presses a pushbutton and selects an image (.bin format) which is displayed in an axis (image_display). No problems there.

Pushbutton Callback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PUSH BUTTON TO LOAD IMAGE FROM FILE
% --- Executes on button press in load_image.
function load_image_Callback(hObject, eventdata, handles)
% hObject handle to load_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.*','Select an file to Process');
image_path=(strcat(pathname,filename)); %Location of the image
% open file in binary read mode
fid = fopen(image_path,'r');
framenumber=2;
columns=1315;
% read image
for n=1:framenumber
    frame=fread(fid,[columns 480],'int16');
end
frame=frame';
set(handles.image_display,'UserData',frame); %Passes the image data to the image_display 'UserData' property

imagesc(frame,'Parent',handles.image_display); %Displays the image in the axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I confirmed that frame (image data) was stored in handles.image_display 'UserData' using breakpoints within the pushbotton callback.

I then want the user to be able to adjust a slider (GainControl) that updates the image by adding contrast. But when I try to perform operations on the data in the slider callback by getting 'UserData', the field is empty. Somehow the data I'm trying to pass to the slider callback isn't getting displayed.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on slider movement.
function GainControl_Callback(hObject, eventdata, handles)
% hObject handle to GainControl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%obtains the slider value from the slider component
GainControl = get(hObject,'Value'); %Slider controls GainControl (contrast)
GainControl = round(GainControl); %The contrast should be an integer
 
%puts the slider value into the edit text component
set(handles.GainControlDisplay,'String', num2str(GainControl));

frame = get(handles.image_display,'UserData'); %Gets image data stored in the axis 'UserData' property
frame = frame*GainControl; %Scales image values (adjust contrast?)
imagesc(frame,'Parent',handles.image_display); %Display the image in the axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Please help!!! Also, generally speaking: I'm clueless as to
-how to best display images that update in a GUI
-pass data between callbacks

Can someone help me with my specific issue in my code and help me understand my general questions above.

Thanks!
Robert

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
handle graphics Robert Berry 25 Nov, 2009 11:24:16
gui Robert Berry 25 Nov, 2009 11:24:16
image processing Robert Berry 25 Nov, 2009 11:24:16
slider Robert Berry 25 Nov, 2009 11:24:16
contrast Robert Berry 25 Nov, 2009 11:24:16
callbacks Robert Berry 25 Nov, 2009 11:24:16
gui Kris Langheinrich 19 Apr, 2008 15:30:06
rssFeed for this Thread

Contact us at files@mathworks.com