saving image after using slider

1 view (last 30 days)
janepear
janepear on 15 May 2013
HI, I have problem with slider.
function slidergamma_Callback(hObject, eventdata, handles)
x=get(hObject,'Value');
imga=handles.imga;
imgas=imga.^x;
axes(handles.axes4);cla;
imshow(imgas);
set(handles.edit1,'String',num2str(x));
update(handles)
%guidata(hObject,handles);
It changes the value of gamma function . The function works but I need to safe image(handles.imga) and there is a problem. When I don´t use guidata(hObject,handles) at the end of the function ,the image is not upgraded and it always save the original image , when i use guidata(hObject,handles) saving works, but slider doesn´t work very well ( it doesn´t get real value of slider but I don´t now maybe it multiply values). Do somebody knows where is the problem?
Thanks a lot
j.

Answers (1)

Image Analyst
Image Analyst on 15 May 2013
Try
imgas= double(imga) .^ x;
axes(handles.axes4);
cla;
imshow(imgas, []); % The [] is important!
  10 Comments
Image Analyst
Image Analyst on 16 May 2013
Well, are you calling imwrite() once or twice? From the code you showed, it looks like you're calling it just once, so why do you think it would save both images? However that was for some button callback, not the slider callback, which you haven't shown yet.
janepear
janepear on 16 May 2013
Edited: janepear on 16 May 2013
ok I call once picture by imread then I save pisture to handles.imga and work with it. I don´t think it save both i think that i save the image in handles.imga ..ok I show you all code And once more i don´t have problem with saving or not working slider i have the problem, that when I use guidata(hObject,handle) the slider (i think) updates every step and save it to handle.imga so I cant´t move by slider more times because I´t not reversible operation. But if i don´t use guidata(hObject,handle) It works, I can change the value and see on the picture how gamma change this picture but i cant save it, becuase( i think) the handle.imga is not updated.
function update(handles)
I=handles.imga;
imga=(I);
handles.imga=imga;
axes(handles.axes8);
imhist(handles.imga);
function pushbuttonload_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonload (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%%%% NACTENI OBRAZU, JEHO INFORMACE A NASTAVENI DO AXES 1 A 2
[soubor cesta]=uigetfile({'*.jpg';'*.bmp';'*.jpeg';'*.png'}, 'Načti obrázek');
filename=fullfile(cesta, soubor);
handles.file=filename;
[fpath, fname, fext]=fileparts(soubor);
validex=({'.bmp','.jpg','.jpeg','.png'});
found=0;
for (x=1:length(validex))
if (strcmpi(fext,validex{x}))
found=1;
imga = imread(filename);
if ndims(imga) == 3
imga = rgb2gray(imga);
end
imga =im2double(imga);
handles.imga = imga;
axes(handles.axes4); cla; imshow(handles.imga);
axes(handles.axes5); cla; imhist(handles.imga);
guidata(hObject,handles);
update(handles)
% --- Executes on button press in pushbuttonsave.
function pushbuttonsave_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonsave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[soubor cesta]= uiputfile('*.jpg','Ulož..');
uloz=[cesta soubor];
imwrite(handles.imga,uloz,'jpg');
function slidergamma_Callback(hObject, eventdata, handles)
% hObject handle to slidergamma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.pushbuttonsave,'Visible','on');
set(handles.pushbutton20,'Visible','off');
x=get(hObject,'Value');
imga=handles.imga;
imgas=imga.^x;
axes(handles.axes4);
cla;
imshow(imgas,[]);
set(handles.edit1,'String',num2str(x));
handles.imga=imgas;
update(handles)
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function slidergamma_CreateFcn(hObject, eventdata, handles)
% hObject handle to slidergamma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in pushbuttongamma.
function pushbuttongamma_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttongamma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=handles.imga;
gamma= x.^0.7 ;
handles.imga=gamma;
axes(handles.axes4);
cla;
imshow(handles.imga);
update(handles);
guidata(hObject,handles);
So the program load picture, then is splot to axes4 and its´ histogram to axes5. If you click on pushbutton it change the image by gamma correction whit value 0.7 and if you want you can change the value yourself.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!