how to call to different image handles for same function callback

조회 수: 2 (최근 30일)
Siddharth Pande
Siddharth Pande 2012년 4월 21일
this a gui call back to load image
% --- Executes on button press in loading_an_image.
function loading_an_image_Callback(hObject, eventdata, handles)
% hObject handle to loading_an_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('*.jpg','select an image file');
image=imread(fullfile(pathname,filename));
handles.image=image;
guidata(hObject,handles);
figure
imshow(image);
axes(handles.axes1);imshow(handles.image);
end
this is the function to perform on the loaded image:
% --- Executes on button press in average.
function average_Callback(hObject, eventdata, handles)
% hObject handle to average (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
image=handles.image
%%gray scale conversion
% the average is done only after the image is...
... converted to a gray scale one
G = rgb2gray(image);
%%function for average filtering
% G is the gray scale image version of the original one
% A is the filtered image
image1 = filter2(fspecial('average',5),G)/255;
guidata(hObject,handles)
figure
imshow(image1);
handles.image1 = image1;
now when i press the push button to get the difference of the image
i am getting a black one i think there is a problem in the handles call back
% --- Executes on button press in subtraction.
function subtraction_Callback(hObject, eventdata, handles)
% hObject handle to subtraction (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% calling the two image
image=get(handles.image);
image1=get(handles.image1);
% subtracting the images
image2=imsubtract(image,image1);
figure
imshow(image2);
guidata(hObject,handles);
handles.image=image2;
axes(handles.axes3);
imshow(handles.image);
end
can any body plz help me in loading the image filtering it and displaying a new one on other axes taking the filtered image subtracting it and showing the output on the third axes.

답변 (3개)

Image Analyst
Image Analyst 2012년 4월 21일
I see a few problems. One is this:
image=get(handles.image);
DON'T override the built-in image() function. Call your variable something else.
The other problem, your main problem, is your subtraction. From the help for imsubtract(), "The array returned, Z, has the same size and class as X unless X is logical, in which case Z is double. If X is an integer array, elements of the output that exceed the range of the integer type are truncated." In other words, if you have uint8 images and any difference would be negative, it will clip them to zero. That, plus the fact that all your differences are probably small, means that your images are black or very dark. Thus instead of imsubtract(), I suggest you do this
differenceImage = double(image1) - double(image2);
imshow(differenceImage, []); % Note, the [] are important.

Siddharth Pande
Siddharth Pande 2012년 4월 23일
mr image analyst still the problem is how to call two image handles for difference i am a newbie in gui so plz help in handles section, what i want is
1)i am loading an image
giving it the name as handles.image=image
2)showing it on axes1
3)taking that image for processing with average filter calling the image as image=handles.image
the o/p image is handles.image=image1
4)displaying that image on axes2
5)subtracting the image for which i m calling both the image image1=handles.image image=handles.image for that i have to call both the original image and the filtered image the o/p image is handles.image=image2 which i am using for histogram
can u help me in the codes
for get(),set();global declerations

Siddharth Pande
Siddharth Pande 2013년 3월 28일
i found the ans it was pretty simple call the handles with different names and every time u call it update the handles in the decleration part

Community Treasure Hunt

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

Start Hunting!

Translated by