how to call to different image handles for same function callback
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (3 件)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!