필터 지우기
필터 지우기

I want to add grid on my image in matlab GUI

조회 수: 2 (최근 30일)
Uzair
Uzair 2013년 5월 15일
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
Image Analyst
Image Analyst 2013년 5월 15일
What is the point of the set(findobj) line?
Uzair
Uzair 2013년 5월 16일
I was trying something i found in another question...anyway...I commented it out later

댓글을 달려면 로그인하십시오.

답변 (2개)

David Sanchez
David Sanchez 2013년 5월 16일
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 2013년 5월 16일
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
Image Analyst
Image Analyst 2013년 5월 16일
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 2013년 5월 16일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by