MATLAB Answers

How to save image that show in axes?

25 views (last 30 days)
Cahaya
Cahaya on 15 Oct 2012
i have this code :
function mCube
load dtRegProp; % data of regionprops
load dtImBiner; % data binary image
dtPsgi = imBinerProp;
imBw = imBiner;
hMainGui = getappdata(0,'hMainGui');
hAxes2 = getappdata(hMainGui,'hAxes2');
axes(hAxes2);
% scale
imScale = imresize(imBw, size(imBw).*[1/2 1]);
% shear
shearMatrix = [1 0 0; -1 1 0; 0 0 1];
shearform = maketform('affine',shearMatrix);
imShear = imtransform(imScale,shearform);
% translation
sisi = mean([dtPsgi.MajorAxisLength,dtPsgi.MinorAxisLength]);
tx = 0;
ty = round(sisi);
transMatrix = [1 0 0; 0 1 0; tx ty 1];
transform = maketform('affine',transMatrix);
imTrans = imtransform(imShear,transform,'xData',[1 size(imScale,2)+ty], ...
'yData',[1 size(imScale,1)+ty]);
% find corner
sigma = 1;
radius = 1;
thresh = 0;
disp = 0;
[rShear,cShear] = harris(imShear,sigma,thresh,radius,disp);
[rTrans,cTrans] = harris(imTrans,sigma,thresh,radius,disp);
% change to real coordinate for display in axes2 in main gui
% 450 is size of an axes
rnShear = 450 - rShear;
rnTrans = 450 - rTrans;
% create line to make a cube, an final result is show in axes2 in
% main gui. In mLine function i use plot function to create line.
for i=1:3:4
hold on;
if mod(i,2) == 0
mLine(cTrans(i),rnTrans(i),cTrans(i-1),rnTrans(i-1));
mLine(cTrans(i),rnTrans(i),cTrans(i-2),rnTrans(i-2));
mLine(cShear(i),rnShear(i),cShear(i-1),rnShear(i-1));
mLine(cShear(i),rnShear(i),cShear(i-2),rnShear(i-2));
else
mLine(cTrans(i),rnTrans(i),cTrans(i+1),rnTrans(i+1));
mLine(cTrans(i),rnTrans(i),cTrans(i+2),rnTrans(i+2));
mLine(cShear(i),rnShear(i),cShear(i+1),rnShear(i+1));
mLine(cShear(i),rnShear(i),cShear(i+2),rnShear(i+2));
end
end
for i=1:4
mLine(cTrans(i),rnTrans(i),cShear(i),rnShear(i));
end
end
In main gui, there's a save button to save image that show in axes2. And i try this code in my save button..
hMainGui = getappdata(0,'hMainGui');
hAxes2 = getappdata(hMainGui,'hAxes2');
axes(hAxes2);
im = getappdata(0,'hImRes');
[fileName,pathName] = uiputfile('*.bmp','BMP Files(*.bmp)','Save as');
name = fullfile(pathName,fileName);
imwrite(img,name);
and my problem is in imwrite(img,name). How i can accommodate the calling function (mLine) in one variable and keep it? Or in other word, looping calling mLine function is to make cube and show in axes, how i can save the result??
Thx u
  1 Comment
Cahaya
Cahaya on 16 Oct 2012
I've try use export_fig and it works well.. Is there another way to save image in axes?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 16 Oct 2012
Edited: Image Analyst on 16 Oct 2012
You can use saveas() to save the whole figure, or imwrite() to save just the image alone. But it doesn't look like you're getting the image, img. In your function, you never assign anything to img.
  1 Comment
Cahaya
Cahaya on 18 Oct 2012
i can't use saveas() cos i save the image in axes. And about assign to img, actually i don't know how to assign the result from call mLine function to img. May i do like this is :
for i=1:3:4
hold on;
if mod(i,2) == 0
img = mLine(cTrans(i),rnTrans(i),cTrans(i-1),rnTrans(i-1));
img = mLine(cTrans(i),rnTrans(i),cTrans(i-2),rnTrans(i-2));
img = mLine(cShear(i),rnShear(i),cShear(i-1),rnShear(i-1));
img = mLine(cShear(i),rnShear(i),cShear(i-2),rnShear(i-2));
else
img = mLine(cTrans(i),rnTrans(i),cTrans(i+1),rnTrans(i+1));
img = mLine(cTrans(i),rnTrans(i),cTrans(i+2),rnTrans(i+2));
img = mLine(cShear(i),rnShear(i),cShear(i+1),rnShear(i+1));
img = mLine(cShear(i),rnShear(i),cShear(i+2),rnShear(i+2));
end
end
is it right?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!