Question

I have an image with a white border around it, and I need to get rid of the border. There are 20 rows of white pixels above the image, 5 columns of white to the left, 5 of white columns to the right, and 5 rows of white below the image. I wan't to crop the image exactly out of that border, how do I do this in matlab? Thanks for any help you can give!

(The image is a tiff, which is why I can't use an online service for this, they won't let me upload .tiff)

Was it helpful?

Solution

What you need is the built-in MATLAB function imcrop. To use it, specify something like

B = imcrop(A,[xmin ymin width height]);

if A is your original image. First find the dimensions of your image. Say its 800 by 600. Then you are looking to crop a 770 by 580 image so these numbers respectively will be your width and height in the above function. Your x and y would be something like 5 and 20, respectively.

OTHER TIPS

U can use imcrop for this if you have image processing toolbox or you can make new image as follows:

I2 = I(21:end-5, 6:end-5)

For 3 dimensions, you can use:

I2 = I(21:end-5,6:end-5,:)

For example as per your comment:

I = rand(153,1510,3);
size(I); %  153        1510           3
I2 = I(21:end-5,6:end-5,:);
size(I2); % 128        1500           3
newIm = oldIm(20:length(oldIm(:,1))-5,5:length(oldIm(1,:))-5)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top