Message Boards Message Boards

0
|
1324 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Selecting the center 256x256 pixels from an image?

Posted 7 months ago

How do I select the center 256x256 pixels from an image? The original image is 626x623 so I have been trying to use a Take statement:

Take[Image[[1]],{29,29+255},{122,122+255}];
POSTED BY: Aidan Vieson
2 Replies

Here is one way - very in accordance with the documentation on ImageTake[]:

(* example-image: *)
img = ImageResize[ExampleData[{"TestImage", "Bridge"}], {626, 623}];
{xdim, ydim} = ImageDimensions[img];
col1 = Round[(xdim - 256)/2];
col2 = col1 + 255;
row1 = Round[(ydim - 256)/2];
row2 = row1 + 255;
img1 = ImageTake[img, {row1, row2}, {col1, col2}]
ImageDimensions[img1]
ImageCompose[img, ImagePad[img1, 1, Red]]
POSTED BY: Henrik Schachner
Posted 7 months ago

There are image-specific functions you could use: ImageTake, ImageTrim, ImageCrop, etc.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract