Reputation: 213
I am using the following lines of code to detect edges in a picture and then overlay the edges detected on the original picture:
A = 'brad.jpg';
B = im2double(imread(A, 'jpg'));
r = 0*B;
r(:,:,1) = B(:,:,1);
g = 0*B;
g(:,:,2) = B(:,:,2);
b = 0*B;
b(:,:,3) = B(:,:,3);
L = medfilt2(r(:,:,1), [3,3]);
L2 = canny_edge(L);
M = medfilt2(g(:,:,2), [3,3]);
M2 = canny_edge(M);
N = medfilt2(b(:,:,3), [3,3]);
N2 = canny_edge(N);
recover = cat(3,L,M,N);
figure, imshow(recover);
black = cat(3, zeros(size(L)),zeros(size(L)), zeros(size(L)));
hold on;
h = imshow(black);
hold off;
set(h, 'AlphaData', L2);
As you can see in the last 4 lines of code, I am overlaying the image with detected edges onto the original picture.
I want to save this new picture (the one with edges overlaying on the original picture). Can someone tell me how to do this? The overlaying picture is only shown to me. Can someone tell me the command to save this? Thanks and Regards.
Upvotes: 1
Views: 836
Reputation: 114796
You can use imshow( ..., 'Border', 'tight');
option for your imshow
commands to eliminate the figure borders. Then you can get the displayed figure as an image using getframe
>> fh = figure;
>> imshow( ..., 'Border', 'tight' ); hold on;
>> h = imshow( black, 'Border', 'tight' ); set( h, 'AlphaData', L2 );
>> f = getframe( fh );
>> imwrite( f.cdata, 'output_image_name.png' );
Upvotes: 1
Reputation: 24127
Try the command saveas
. To find more information about options (such as the file format to save to), type doc saveas
.
Upvotes: 1