Code covered by the BSD License  

Highlights from
crop whitespace from an image


4.9 | 14 ratings Rate this file 30 Downloads (last 30 days) File Size: 2.4 KB File ID: #20427

crop whitespace from an image



24 Jun 2008 (Updated )

CROP gets rid of whitespace around an image

| Watch this File

File Information

CROP(FILENAME,APPEND,MARGIN) is the full calling form. APPEND and MARGIN are optional inputs.

CROP('filename.ext') crops the image in the file and saves it using the original filename, overwriting the old image. The extension (ext) can be anything IMREAD supports.

CROP(directory) crops all images in a directory.

If APPEND is 1, CROP saves the cropped image as 'filename_crop.ext' in the same directory as the original.

MARGIN sets the margin width in pixels (default is 10).

Example: crop('C:\MATLAB7\toolbox\matlab\demos\html\cruller_01.png',1)

Requirements: your FIND must allow the 'last' option (version 7+?)

MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
17 Feb 2014 Cheryl Harrison

Love this script. Use it all the time, brilliant.

11 Oct 2013 Ben

Can I nominate this for script of the year? This is amazing. I wish I knew about this script earlier.

16 Jul 2013 Stefano

Just Perfect, thanks!

23 May 2013 Dani

where is the file???? anybody send me on my email id?
thanks in advance..

30 Aug 2012 Andrew Bliss

Johan- it shouldn't change the colors. Can you give more details or an example file?

20 Jul 2012 Johan

Very helpful but does anybody know why it changes the colours of the picture ?

19 Jul 2012 Leo

Very useful. Works like a charm.

16 Jul 2012 Sean  
09 Apr 2012 TAFKARS

Nice job, thanks very much.

04 Mar 2012 ali

I tried savefig but it doesn't crop, this one works great! Keeps me from manually cropping every time with another software

13 May 2011 Mohsen Jamali

Works very nice, thanks.

10 Mar 2011 Maja

Thank you, thank you, thank you!

24 Dec 2010 even coil

very helpful, thank you

04 Oct 2010 curran eggertson

I wish I had found this earlier. This could have saved me manually cropping about 300 images already, but atleast still saves the next 700.

09 Sep 2010 Mike Hoff

Wow! This just saved me a wealth of time, Thank you so much!!! No more opening each image one by one in Picture Manager and manually cropping

22 May 2010 Maider Marin

very usefull, Thanks

23 Feb 2009 Clayton Stanley

Great little *.m file!
Modified it a bit, but more-or-less ready to go.
Thanks a bunch!

31 Aug 2008 Tom Close

Saved me pulling my hair out trying to work this out!

01 Jun 2012

I improved the input checks and comments. Code now handles transparency in .png files. MARGIN is now an input.

Contact us