Unable to do subtraction of images in GUI
Show older comments
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.
Accepted Answer
More Answers (1)
ytzhak goussha
on 9 Jun 2021
0 votes
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 Comments
Warid Islam
on 11 Jun 2021
Edited: Warid Islam
on 11 Jun 2021
Walter Roberson
on 11 Jun 2021
value1 = handles.value1; %(this is the index of the image in the cell array i geuss)
orig_imgs1 = handles.InputImage1{value1}; %(this is one image)
output_img1 = handles.InputImage2{value1}; %(this is one image)
ytzhak goussha
on 11 Jun 2021
It is possible that it is sometimes a matrix when it's only one image, and a cell array when it is more.
try to add this line before the subtraction:
and make sure that the variable "value1" is not empty.
if ~iscell(orig_imgs1)
orig_imgs1 = {orig_imgs1};
end
if ~iscell(orig_imgs2)
orig_imgs1 = {orig_imgs2};
end
You can also pause set the app to pause at errors to check this out or add a line that prints out the class of your variables
disp(class(orig_imgs1))
disp(class(orig_imgs2))
Warid Islam
on 12 Jun 2021
Walter Roberson
on 12 Jun 2021
Try
imshow(dblSubtractedImage, [], 'parent', handles.axes3);
Warid Islam
on 12 Jun 2021
Warid Islam
on 12 Jun 2021
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!