scripting - Automatic cropping of pictures -


I have many photos that are made of an object with a black background, I have created them with Matlab, and their A white "extra" is all around the close photo, so I want to be able to crop them automatically so that the white in the photo is not extra.

Files .tif format

Here's an example as an example:  Enter image details here

This may not be noticeable at first, but if you select the picture, then it's just black area Very big in comparison.

You can just throw in those rows and columns that have only one.

 % # Read image [IMG, map] = Reader ('http://i.stack.imgur.com/Yyz8Z.png'); % # Is placed in rows / colons which have 1 img = img (any (img & lt; 1,2), other than any (IMG & lt; 1,1) values;);   

For RGB shocks, you can use (assuming the maximum value in the TIFF image is 86, as in PNG)

  Img = img ~ all (all (img == max (img (:)), 3), 2), ~ all (all (img == max (img (:)), 3), 1), :);    

Edit

There are a few ways to make sure that you are not able to get the limit in the first place. For example, if you want to save the m-by-n-by-3 RGB image array, you can use

  to write imwrite (imageArray, 'myFile.tif') Alternatively, if you have a shape that you want to save without limits, you can call the axes handle to get the image:  
  axeshandle = gca; To handle the current figure of axes to #% f = getframe (axesHandle); Imwrite (f.cdata, 'myFile.tif');   

If you want to save your shape with aliasing, you can make excellent use of file exchange.

Comments