Borrar filtros
Borrar filtros

I want to add grid on my image in matlab GUI

1 visualización (últimos 30 días)
Uzair
Uzair el 15 de Mayo de 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 comentarios
Image Analyst
Image Analyst el 15 de Mayo de 2013
What is the point of the set(findobj) line?
Uzair
Uzair el 16 de Mayo de 2013
I was trying something i found in another question...anyway...I commented it out later

Iniciar sesión para comentar.

Respuestas (2)

David Sanchez
David Sanchez el 16 de Mayo de 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 el 16 de Mayo de 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 comentarios
Image Analyst
Image Analyst el 16 de Mayo de 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 el 16 de Mayo de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by