Effacer les filtres
Effacer les filtres

I want to add grid on my image in matlab GUI

1 vue (au cours des 30 derniers jours)
Uzair
Uzair le 15 Mai 2013
I have a problem. Below is my code...when ever i check the box, the image is replaced with blank screen with a vertical line in middle..Help me please
function show_grid_Callback(hObject, eventdata, handles) % hObject handle to show_grid (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if (get(handles.show_grid, 'Value')) % rgb = imread('IK.jpg');
imshow(handles.img,'Parent', handles.axes3);
hold on
M = size(handles.img,1);
N = size(handles.img,2);
a=str2double(get(handles.edit3, 'String')); b=str2double(get(handles.edit5, 'String'));
for k = 1:a:M x = [1 N]; y = [k k];
plot(x,y,'Color','black','LineStyle','-','Parent', handles.axes3);
set(findobj('Tag','MyGrid'),'Visible','on')
% plot(x,y,'Color','k','LineStyle',':');
end
for k = 1:b:N x = [k k]; y = [1 M];
plot(x,y,'Color','black','LineStyle','-','Parent', handles.axes3);
set(findobj('Tag','MyGrid'),'Visible','on')
% plot(x,y,'Color','k','LineStyle',':');
end
hold off else imshow(handles.img,'Parent', handles.axes3); end % Hint: get(hObject,'Value') returns toggle state of show_grid guidata(hObject, handles);
  2 commentaires
Image Analyst
Image Analyst le 15 Mai 2013
What is the point of the set(findobj) line?
Uzair
Uzair le 16 Mai 2013
I was trying something i found in another question...anyway...I commented it out later

Connectez-vous pour commenter.

Réponses (2)

David Sanchez
David Sanchez le 16 Mai 2013
Image Analyst is right. I simplified the code to this:
I = imread('cameraman.tif');
imshow(I)
hold on
M = size(I,1);
N = size(I,2);
a=5;
b=10;
for k = 1:a:M
x = [1 N];
y = [k k];
plot(x,y,'Color','black','LineStyle','-');
set(findobj('Tag','MyGrid'),'Visible','on')
end
for k = 1:b:N
x = [k k];
y = [1 M];
plot(x,y,'Color','black','LineStyle','-');
set(findobj('Tag','MyGrid'),'Visible','on')
end
hold off
And the desired grid shows up. The problem might be in the figure handle.

David Sanchez
David Sanchez le 16 Mai 2013
You get a vertical line because you are plotting a vertical line. The values of both elements of your x array are the same
x=[k k];
which will end up in a vertical line whatever the values of y are.
... ... for k = 1:b:N x = [k k]; y = [1 M];
plot(x,y,'Color','black','LineStyle','-','Parent', handles.axes3);
set(findobj('Tag','MyGrid'),'Visible','on')
% plot(x,y,'Color','k','LineStyle',':');
end
  3 commentaires
Image Analyst
Image Analyst le 16 Mai 2013
But he didn't always have the same x. k went from 1 to N in steps of b and he had hold on so it should have drawn and retained lots of vertical lines, not just one. Just off the top of my head it looks like he should have had vertical lines at 1, (1+b), (1+2*b), .... etc.
Uzair
Uzair le 16 Mai 2013
Al tough code works perfectly fine when i run it seperately...but when i modify this code for my GUI ...it's give me wrong results

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by