Unable to do subtraction of images in GUI
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Warid Islam
le 9 Juin 2021
Commenté : Warid Islam
le 14 Juin 2021
Hi,
I have built a matlab GUi where I load two separate sets of images in two different axes. I want to subtract each of the both sets of images from each other and display the result in another image axes(axes3). I would browse through each set of images from the first two image axes using a image slider. Their corresponding subtraction result would be displayed in the third axes. However , I am getting an error message.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value1=handles.value1;
orig_imgs1 = handles.InputImage1;
output_img1=handles.InputImage2;
handles.dblSubtractedImage = {};
[rowsorig_imgs1 colsorig_imgs1 numberOfColorChannelsorig_imgs1]=size(orig_imgs1);
[rowsoutput_img1 colsoutput_img1 numberOfColorChannelsoutput_img1]=size(output_img1);
if rowsoutput_img1 ~= rowsorig_imgs1 || colsorig_imgs1 ~= colsoutput_img1
output_img1 = imresize(output_img1, [rowsorig_imgs1 colsorig_imgs1]);
end
dblSubtractedImage = (orig_imgs1{value1}) - (output_img1{value1});
imshow(dblSubtractedImage,'parent',handles.axes3);
handles.dblSubtractedImage{end+1}= dblSubtractedImage;
guidata(hObject, handles);
end
I get the following error message:
Error using imresize>parsePreMethodArgs (line 379)
Invalid input syntax; input image missing from argument list.
Error in imresize>parseInputs (line 273)
parsePreMethodArgs(varargin, method_arg_idx, first_param_string_idx);
Error in imresize (line 152)
params = parseInputs(args{:});
Error in ng>pushbutton3_Callback (line 226)
output_img1 = imresize(output_img1, [rowsorig_imgs1 colsorig_imgs1]);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ng (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ng('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
0 commentaires
Réponse acceptée
Image Analyst
le 12 Juin 2021
What is this????
InputImage2 = imresize(InputImage2(value1), [rowsInputImage1 colsInputImage1]);
You're saying the image is InputImage2(value1). So what is value1? Is it an integer or a vector? So if value1 is an integer then you're basically using it as the linear index into the InputImage2 image, which gives you only a single pixel. Then you blow up this pixel to a whole image with imresize - so now you have a totally uniform image. Now you subtract that from InputImage1 and it will just look like a dark version of InputImage1. However you used [] in imshow() to scale the image to fit the dynamic range so of course it will look identical to InputImage1.
Try
InputImage2 = imresize(InputImage2, [rowsInputImage1 colsInputImage1]);
and when you subtract, cast the images to double or else negative numbers will get clipped.
dblSubtractedImage = double(InputImage1) - double(InputImage2);
or you can use imabsdiff(), which essentially flips negative numbers positive.
dblSubtractedImage = imabsdiff(InputImage1, InputImage2);
12 commentaires
Plus de réponses (1)
ytzhak goussha
le 9 Juin 2021
I think that the problem is that you are trying to resize an image in a cell array
value1=handles.value1; (this is the index of the image in the cell array i geuss)
orig_imgs1 = handles.InputImage1; (this is a cell array of images)
output_img1=handles.InputImage2; (this is a cell array of images)
handles.dblSubtractedImage = {};
[rowsorig_imgs1 colsorig_imgs1 numberOfColorChannelsorig_imgs1]=size(orig_imgs1);
[rowsoutput_img1 colsoutput_img1 numberOfColorChannelsoutput_img1]=size(output_img1);
if rowsoutput_img1 ~= rowsorig_imgs1 || colsorig_imgs1 ~= colsoutput_img1
output_img1 = imresize(output_img1{value1}, [rowsorig_imgs1 colsorig_imgs1]); (here you must specify which image you want to resize)
end
dblSubtractedImage = (orig_imgs1{value1}) - (output_img1{value1});
imshow(dblSubtractedImage,'parent',handles.axes3);
handles.dblSubtractedImage{end+1}= dblSubtractedImage;
guidata(hObject, handles);
end
7 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!