Thread Subject: imcrop

Subject: imcrop

From: Jack Branning

Date: 30 May, 2008 19:39:01

Message: 1 of 6

Hi there,

Does anyone know how I can use 'imcrop' to crop 4 pixels from the left of the
image, and 4 pixels to the right of the image.

I need the program to be able to do this by itself, possibly by using:

size(image, 1)-4 and size(image, 2)-4

This means that i cannot rely on the graphical side of things that imcrop offers.

Many thanks in advance.

Jack

Subject: imcrop

From: Kenneth Eaton

Date: 30 May, 2008 20:00:22

Message: 2 of 6

"Jack Branning" <jbr.nospam@nospam.com> wrote in message
<g1pl4l$dsg$1@fred.mathworks.com>...
> Hi there,
>
> Does anyone know how I can use 'imcrop' to crop 4 pixels
from the left of the
> image, and 4 pixels to the right of the image.
>
> I need the program to be able to do this by itself,
possibly by using:
>
> size(image, 1)-4 and size(image, 2)-4
>
> This means that i cannot rely on the graphical side of
things that imcrop offers.
>
> Many thanks in advance.
>
> Jack

Could you just use a subindex into the image matrix?

ex: img = img(5:(size(img,1)-4)),:,:);

Ken

Subject: imcrop

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 May, 2008 20:42:56

Message: 3 of 6

In article <g1pmcm$t6b$1@fred.mathworks.com>,
Kenneth Eaton <Kenneth.dot.Eaton@cchmc.dot.org> wrote:

>Could you just use a subindex into the image matrix?

>ex: img = img(5:(size(img,1)-4)),:,:);

img = img(5:end-4,:,:);


>> I need the program to be able to do this by itself,
possibly by using:
>>
>> size(image, 1)-4 and size(image, 2)-4

If you are looking at size(image,1) and size(image,2) then
either that was a mistake or you want to crop slightly differently
than you indicated (left and right).

here's an example of cropping left and bottom, leaving right
and top alone:

croppedimage = img(5:end,1:end-4);

Mind you, which dimension is "top" is open to interpretation when
you are working at the array level, and depends upon how you
display the image -- i.e., should the logical origin be at the
lower-left corner, or at the upper-left corner ?
--
  "The human mind is so strangely capricious, that, when freed from
  the pressure of real misery, it becomes open and sensitive to the
  ideal apprehension of ideal calamities." -- Sir Walter Scott

Subject: imcrop

From: Jack Branning

Date: 30 May, 2008 22:44:02

Message: 4 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message
<g1posg$crb$1@canopus.cc.umanitoba.ca>...
> In article <g1pmcm$t6b$1@fred.mathworks.com>,
> Kenneth Eaton <Kenneth.dot.Eaton@cchmc.dot.org> wrote:
>
> >Could you just use a subindex into the image matrix?
>
> >ex: img = img(5:(size(img,1)-4)),:,:);
>
> img = img(5:end-4,:,:);
>
>
> >> I need the program to be able to do this by itself,
> possibly by using:
> >>
> >> size(image, 1)-4 and size(image, 2)-4
>
> If you are looking at size(image,1) and size(image,2) then
> either that was a mistake or you want to crop slightly differently
> than you indicated (left and right).
>
> here's an example of cropping left and bottom, leaving right
> and top alone:
>
> croppedimage = img(5:end,1:end-4);
>
> Mind you, which dimension is "top" is open to interpretation when
> you are working at the array level, and depends upon how you
> display the image -- i.e., should the logical origin be at the
> lower-left corner, or at the upper-left corner ?
> --
> "The human mind is so strangely capricious, that, when freed from
> the pressure of real misery, it becomes open and sensitive to the
> ideal apprehension of ideal calamities." -- Sir Walter Scott


Apologies, I did make a mistake. I need to crop 4 pixels from the left, and 4
from the right. It's 8 pixels in total but it must only be 4 pixels from either
side. How would I do that?

Subject: imcrop

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 May, 2008 22:54:04

Message: 5 of 6

In article <g1pvvi$edd$1@fred.mathworks.com>,
Jack Branning <jbr.nospam@nospam.com> wrote:

>I need to crop 4 pixels from the left, and 4
>from the right. It's 8 pixels in total but it must only be 4 pixels from either
>side. How would I do that?

My previous code was close, but was cropping top and bottom rather
than left and right. Here is the revised code:

croppedimage = img(:,5:end-4,:);

This presumes that img is RGB. If img is only 2 dimensional, then

croppedimage = img(:,5:end-4);

--
  "I buy more from my grocer than he buys from me, and I bet it's
  the same with you and your grocer. That means we have a trade
  deficit with our grocers. Does our perpetual grocer trade deficit
  portend doom?" -- Walter Williams

Subject: imcrop

From: Jack Branning

Date: 30 May, 2008 23:04:01

Message: 6 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message
<g1q0ic$nmh$1@canopus.cc.umanitoba.ca>...
> In article <g1pvvi$edd$1@fred.mathworks.com>,
> Jack Branning <jbr.nospam@nospam.com> wrote:
>
> >I need to crop 4 pixels from the left, and 4
> >from the right. It's 8 pixels in total but it must only be 4 pixels from
either
> >side. How would I do that?
>
> My previous code was close, but was cropping top and bottom rather
> than left and right. Here is the revised code:
>
> croppedimage = img(:,5:end-4,:);
>
> This presumes that img is RGB. If img is only 2 dimensional, then
>
> croppedimage = img(:,5:end-4);
>
> --
> "I buy more from my grocer than he buys from me, and I bet it's
> the same with you and your grocer. That means we have a trade
> deficit with our grocers. Does our perpetual grocer trade deficit
> portend doom?" -- Walter Williams


That works perfectly, thank you so much!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
imcrop Jack Branning 30 May, 2008 15:40:23
cropping Jack Branning 30 May, 2008 15:40:23
pixels Jack Branning 30 May, 2008 15:40:23
rssFeed for this Thread

Contact us at files@mathworks.com