Why are my axes-objects non-existent?
2 views (last 30 days)
Show older comments
Hello,
I'm working on a programm to load a image in one axes-object and make a affine transformation of this one, then save the transformation in a second axes. The axes-objects are squares of the same size. Afterwards i register the (previously given) transformation parameters by clicking 3 points in both pictures and calculationg them. After all that, when i press the mousebutton and "draw" in the first axes (original bild) my drawing should be transformed and drawn in the transformed image as well. But when I want to draw in the first axes i get an error:
Error while evaluating figure WindowButtonMotionFcn
Reference to non-existent field 'axes1'.
Error in Aufgabe2_neu>figure1_WindowButtonMotionFcn (line 178) plot(handles.axes1, mouse(1,1), mouse(1,2), 'r-');
I'll give you some of my code that i think is relevant:
if true
% code
function axes1_CreateFcn(hObject, eventdata, handles)
global C;
global a1Pos;
%global ha1;
%ha1 = handles.axes1;
a1Pos = get(gca,'Position');
A = imread('beach.jpg');
C = imcrop(A, [150 150 a1Pos(3) a1Pos(4)]);
image(C);
end
-----------------------------------------------------
if true
% code
function axes2_CreateFcn(hObject, eventdata, handles)
global C;
global a1Pos;
%global ha2;
%ha2 = handles;
a = -1+2*(28/31);
b = -1+2*(1/12);
c = -1+2*(1992/1980);
d = 1;
tx = 0;
ty = 0;
if(isempty(a1Pos))
a1Pos = get (handles.axes1, 'Position');
end
if(isempty(C))
A = imread('beach.jpg');
C = imcrop(A, [150 150 a1Pos(3) a1Pos(4)]);
image(C);
end
abb = [a b 0; c d 0; tx ty 1];
ts = maketform('affine', abb);
D = imtransform(C,ts);
D = imcrop (D, [100 100 a1Pos(3) a1Pos(4)]);
imshow(D,'InitialMagnification',100);
end
if true
% code
end
if true
% code
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
global klicks;
global mouse;
global PM;
global druck;
global e;
global f;
global g;
global h;
global sx;
global sy;
global msgicon;
druck = true;
if klicks<6
mouse = get(gca,'currentpoint');
hold on
plot(mouse(1,1),mouse(1,2),'c.');
PM(klicks+1,1) = mouse(1,1);
PM(klicks+1,2) = mouse(1,2);
klicks = klicks + 1;
if klicks == 1
h = msgbox('Klicken sie nun den entsprechenden Punkt im rechten Bild an', 'Info','custom',msgicon);
end
if klicks == 2
h = msgbox('Wiederholen Sie diesen Vorgang nun noch 2 mal.', 'Info','custom',msgicon);
end
end
if klicks==6
M1 = [PM(1,1)-PM(3,1) PM(1,2)-PM(3,2) 0 0;
0 0 PM(1,1)-PM(3,1) PM(1,2)-PM(3,2);
PM(1,1)-PM(5,1) PM(1,2)-PM(5,2) 0 0;
0 0 PM(1,1)-PM(5,1) PM(1,2)-PM(5,2)]
M2 = [PM(2,1)-PM(4,1);PM(2,2)-PM(4,2);PM(2,1)-PM(6,1);PM(2,2)-PM(6,2)];
efgh = M1\M2;
e = efgh(1,1);
f = efgh(2,1);
g = efgh(3,1);
h = efgh(4,1);
sx = PM(2,1) - (e*PM(1,1)+f*PM(1,2));
sy = PM(2,2) - (g*PM(1,1)+h*PM(1,2));
klicks = klicks +1;
end
end
if true
% code
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
global klicks; global mouse; global e; global f; global g; global h; global sx; global sy; global druck; global ha1; %global ha2;
if klicks >=7 mouse = get(gca,'currentpoint'); px = e*mouse(1,1) + f*mouse(1,2) + sx; py = g*mouse(1,1) + h*mouse(1,2) + sy;
if druck == true
plot(mouse(1,1), mouse(1,2), 'r-');
hold on
plot(handles.axes2, px, py, 'b.');
end
end
end
I know i could leave out the handles.axes1. It will paint in that axes then but then I'll get the same error for axes2 stating that it isn't existent... Does anyone know a solution to this?
Thanks and best regards, Daniel
0 Comments
Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!