MATLAB GUI not working as expected

3 次查看(过去 30 天)
Hi,
I am completing a univeristy assignment which is to create a GUI with various edge detection methods and to write our own method. As can be see from the first image below, the edge detection methods work well and display correctly, however when selecting my own method the final step, adding a white border, is applied to the wrong image (see second image).
I have attached the .m file for reference. I believe the error is towards the bottom of the my_own_method function.
Does any one know how I can apply the my_own_method function to axis 2 only?
Thanks

采纳的回答

Cris LaPierre
Cris LaPierre 2020-4-11
It looks like the other edge detection methods are just loading an image of the result rather than actually processing the result.
When you plot your results, you are not specifying where to plot, so it is by default plotting them on the current axes (the last one that was used). This tends to be the one where the police image was added.
To fix this, makes axes2 the current axis before turning hold on and plotting. The line of code for doing this is already in each of case statements for the other methods:
axes(handles.axes2);
If you really want to be sure, you could also specify the axes to plot into as part of your plot command (though you still have to turn hold on). So your plot code might look like this.
...
axes(handles.axes2);
hold on
for k = 1:length(B)
boundary = B{k};
plot(handles.axes2,boundary(:,2),boundary(:,1),'w','LineWidth',2)
end
hold off
Don't forget, it's always best practice to also turn hold off.
  10 个评论
Cris LaPierre
Cris LaPierre 2020-4-18
编辑:Cris LaPierre 2020-4-19
The reason they are not appearing is because of the order you are plotting your images in. You immediately overwrite the boundaries with the imshow command in your try-catch statement.
Now that I have the fig file, I was able to play around. It ends up you do not need to pass handles to my_own_method after all. Instead, keep all your plotting in the same place (the try-catch statement in popupmenu1_Callback). Move your plotting of the boundaries to the catch statement, and just add the boundaries as a second output from my_own_method.
Update your "Own Method" catch statement to the following
...
case 'Own Method'
[img2,B] = my_own_method(img);
axes(handles.axes2);
imshow(img2);
hold on
for k = 1:length(B)
boundary = B{k};
plot(handles.axes2,boundary(:,2),boundary(:,1),'w','LineWidth',2)
end
Update "my_own_method" accordingly
function [imgOut,B] = my_own_method(img)
% Identifying the Thresholds of the Image
I = rgb2gray(img);
bw = imbinarize(I);
% Remove any object/threshold of object that is less than 30 pixels
bw = bwareaopen(bw,30);
% Close any gaps
se =strel('disk',2);
bw = imclose(bw,se);
% Fill the thresholds in
bw = imfill(bw,'holes');
% Identify the outer boundary of the fill items
[B,L] = bwboundaries(bw,'noholes');
% Fill the inner boundary in and show the image
imgOut = label2rgb(L,@jet,[.5 .5 .5]);
When I run this, I get the following output without any errors.
Ellen Taylor
Ellen Taylor 2020-4-19
Cris, thank you so much for all your help. :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by