Richard Dong
Richard Dong

Reputation: 704

How to convert image to EPS file without leaving any margins with MATLAB?

I am converting images to EPS files with the following script.

%% Image 2 eps file.
% - img: the image.
% - eps: eps filename.
function Image2Eps(img, eps)
    imshow(img,'border','tight','InitialMagnification',100);
    print(gcf,'-depsc',eps);
end

The file generated almost bound the image tightly. But a small margin is always left on the top and on the right side. How to make the EPS file exactly the size of the bitmap image?

Upvotes: 3

Views: 898

Answers (1)

Shai
Shai

Reputation: 114926

If you are not too locked on Matlab. You can use Image Magick to do the conversion. I used it in a command line:

imgtops2.exe imge.ppm -e -c 0,0 -o image.eps

I used it on a Windows machine, but I believe they have working binaries for other OS as well.

Furthermore, once you have a working command line in dos or shell you can call it from Matlab using system, dos or unix commands.

PS.

I used an old version of ImageMagick, in more recent releases they might have changed imgtops2 to convert, you'll have to look at their documentation.

Upvotes: 0

Related Questions