Not enough input arguments error when using imshow

1 次查看(过去 30 天)
Hi, since i havent found a solution to my problem i am asking you guys for your help. I have build a GUI with GUIDE. First the function was a script and it worked fine, since i changed it to a function i get the error. The reason i changed it is, that i also have a slider and want to update the threshold constantly and that didnt work out well with a script.
it works fine until i get to the "switch choice". Doesn't matter wich case i choose i always get the following error.
----------------------
Error while evaluating UIControl Callback
Error using Detection_plot (line 31)
Not enough input arguments.
Error in DetectionGUIv1>EdgeDet_Callback (line 116)
Detection_plot;
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in DetectionGUIv1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)DetectionGUIv1('EdgeDet_Callback',hObject,eventdata,guidata(hObject))
----------------------------------------------
NOTE: function EdgeDet_Callback and function Detection_plot are not in the same file
% --- Executes on button press in EdgeDet.
function EdgeDet_Callback(hObject, eventdata, handles)
% hObject handle to EdgeDet (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
Detection_plot;
guidata(hObject, handles);
_____________________________
%%%Function to Callback%%%%%%
------------------------------
function Detection_plot (hObject, eventdata, handles)
%Read the saved Roughness image
RemoveWhiteSpace([], 'file', 'Roughness.png', 'output', 'Roughness1.png');
I=imread('Roughness1.png');
imshow(I, 'Border', 'tight')
%Selection of the needed Area in the image
choice = questdlg('Use the whole image or do you want to crop the image?', ...
'Image Area', ...
'Use full image', 'Use cropped image','Use cropped image');
switch choice
case 'Use full image'
I2 = imread('Roughness1.png');
imshow(I2,'Parent', handles.axes1);
case 'Use cropped image'
[I2, rect] = imcrop(I);
imshow(I2,'Parent', handles.axes1);
end
imshow(I2,'Parent', handles.axes1);
guidata(hObject, handles);
%convert image to black&white
I2 = rgb2gray(I2);
%Generate Gradient Image of BW-Image (lets see if that works better)
[Gx, Gy] = imgradientxy(I2);
[Gmag, Gdir] = imgradient(Gx, Gy);
%imshow(Gmag, []), title('Gradient Magnitude')
%Apply Edge Detection
SliderVal = get(handles.Tresh, 'Value');
BW = edge(Gmag,'Canny',SliderVal);
iptsetpref('ImshowBorder','tight');
%BW = imfill(BW, 'holes')
%imshow(BW);
end
So, i would be really happy if anyone of you could help me. Thank you

回答(1 个)

ag
ag 2025-4-13
Hi Markus,
The error message "Error using Detection_plot (line 31): Not enough input arguments" indicates that the function "Detection_plot" is being called with fewer input arguments than expected.
Upon reviewing the code you provided, it appears that the function "EdgeDet_Callback" is calling "Detection_plot" without any input arguments. Below is a revised version of your code snippet that addresses this issue:
function EdgeDet_Callback(hObject, eventdata, handles)
%rest of the code
Detection_plot(hObject, eventdata, handles);
end
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by