fb.junks
fb.junks

Reputation: 15

MATLAB: Remove white background in 'saveas' function

I am cropping a image in matlab 2013a with imcrop and saving it by using the function saveas. The issue I face is that a white background is save with the image although the figure shown by imshow only shows the image without the white background. Need help to remove that white background

CODE:

clc
clear all
close all
I1=imread('IMG_1956.jpg');
I=imshow('IMG_1956.jpg');

h=imrect(gca,[0 0 270 125]);
pause
pos=getPosition(h);
s=imcrop(I1,pos);
na='IMG_1956.jpg';
na=na(1:end-4);
fi=strcat(na, '_.png');
H=imshow(s)
saveas(H,fi);

Upvotes: 0

Views: 672

Answers (1)

Yvon
Yvon

Reputation: 2983

This one works for me.

I1=imread('Jellyfish.jpg');
I=imshow('Jellyfish.jpg');

h=imrect(gca,[0 0 270 125]);
pause
pos=getPosition(h);
s=imcrop(I1,pos);
na='Jellyfish.jpg';
na=na(1:end-4);
fi=strcat(na, '_.png');
H=imshow(s)
imwrite(s,fi);

Solution: Use imwrite with H.CData or s

Upvotes: 1

Related Questions