Is it possible to snip a certain number of pixels from a specified side of an image, without specifying the image's final width and height?

It seems that ImageCrop allows one to specify the final size of the image. For example, ImageCrop[image, size, spec] crops image image to size size, and one can specify which side of the image the pixels should be taken from, using spec.

But, what if I don't know the final size size of the image? What if I just want to snip 10 pixels from the right side of the image? I might want to do this for a series of images, whose sizes are not known (at least immediately).

-

Same basic solution using image take but wrapped up a little:

img = Import["ExampleData/rose.gif"];


Crop[img_, {{dxl_, dxr_}, {dyl_, dyu_}}] := ImageTake[img, {dyl, -dyu}, {dxl, -dxr}]


Where dxl, dxr, dyl, dyu represent the x lext, x right, y lower and y upper sizes of crop.

Crop[img,{{10, 10}, {25, 25}}]


Removes 10 pixels from the left and right edges and 25 from the bottom and top.

You can then apply the same trim a group of images held in a list, by the following

images={im1,im2,im3,im4,...,imn};

Crop[#,{{0,10},{5,0}}]&/@images

-
When ImageTake is provided with negative arguments, it counts down from ImageDimensions, like Part –  belisarius Jul 24 '12 at 20:11
@belisarius Thanks for that, I didn't really pick that up from the docs. Which reduces this pretty much to the same as your solution :) –  image_doctor Jul 24 '12 at 22:15
From the help -n ... last n elements :) –  belisarius Jul 24 '12 at 23:16
@Belisarius It must be the way I read them :) I took, ImageTake[image,-n] gives an image consisting of the last n rows of image to mean you got rows N-n+1 to N, not, 0 to N-n. As in -3 gives you the last 3 rows, not everything but the last 3 rows. –  image_doctor Jul 24 '12 at 23:22
Well, you know: Mma docs have been written by 10^7 monkeys –  belisarius Jul 24 '12 at 23:28

ImageTake[i, All, {1, -11}]


Examples:

img = Import["ExampleData/rose.gif"];
ImageTake[img, {25, -25}, {10, -10}]


ImageTake[ExampleData[{"TestImage", "Lena"}], {180, -180}, {180, -180}]


-
Thanks! OK, I need to specify size as All. Cool! –  Andrew Jul 24 '12 at 19:37
@MatthiasOdisio OBOE :) –  belisarius Jul 27 '12 at 18:21

As an alternative to ImageTake, ImagePad will do the job using the syntax ImagePad[img, {{left, right}, {bottom, top}}]:

img = Import["ExampleData/rose.gif"];
In[10]:= ImagePad[img, {{0, -10}, {0, 0}}] == ImageTake[img, All, {1, -11}]
Out[10]= True


Note the difference between taking up to the last minus 10th column and removing 10 columns.

-