- Home
- Search
- Contributors
- Recent Activity
- Flagged Content
- Log in to ask and answer questions.
- Ask a Question
- About MATLAB Answers

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Cesar
on 5 Feb 2013

how to obtain image boundary of an image?

Answer by Image Analyst
on 5 Feb 2013

Accepted answer

You haven't explained this well enough to answer. The answer could be to use bwperim(), or bwboundaries(), or just to take the first and last row and first and last column. Are you going to explain further what you want?

Show 23 older comments

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127198

I want to perform a boundary operation by which to obtain image boundary on a gray image.

Image Analyst
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127226

OK, bwboundaries() and bwperim() only work on binary images. So, just do something like this:

leftBoundary = yourImage(:, 1); rightBoundary = yourImage(:, end); topBoundary = yourImage(1, :); bottomBoundary = yourImage(end, :);

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127313

Thanks. The functions do create and display all 4 boundaries of the image. Can that also be done using only 1 function?

Image Analyst
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127345

Yes, just string them together:

oneBoundary = [yourImage(:,1), yourImage(:,end), yourImage(1,:), yourImage(end,1)];

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127350

I got an error using the string: Error using horzcat CAT arguments dimensions are not consistent.

Image Analyst
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127363

You need to transpose two of them, because two are row vectors and two are column vectors. Use ' to transpose.

oneBoundary = [yourImage(:,1)', yourImage(:,end)', yourImage(1,:), yourImage(end,1)];

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127371

Thanks. Makes sense.

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127372

Another question. Imagine an image with 4 birds (bird.tif by example), how to add additional bird in the image?

Image Analyst
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127386

Get a mask for the bird, then do

birds5(binaryMask) = singleBirdImage(binaryMask);

to transfer the bird from the singleBirdImage to the birds5 image.

Cesar
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127388

img = imread('bird.tif'); IMG = imshow(img); IMG1 = imellipse(gca,[55 10 120 120]); BW = createMask(IMG1,IMG); Will that create the mask for the bird?

Image Analyst
on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127396

Why don't you upload your images of the 4 birds? Where does your single bird come from? A separate image, or is it just one of the 4 that you'd like to copy somewhere else in the image? If you upload your images, then we can cut to the chase and not go back and forth lots of times.

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127413

How do I upload the image?

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127416

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127419

Done

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127424

Uh, OK.

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127535

Any update?

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127540

On what?

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127551

After uploading the image, do you have an answer?

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127555

What image? You didn't tell me the location of any image. Please review your postings from my point of view. Does anyone have enough information to help you?

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127560

Why don't you upload your images of the 4 birds? Where does your single bird come from? A separate image, or is it just one of the 4 that you'd like to copy somewhere else in the image? If you upload your images, then we can cut to the chase and not go back and forth lots of times.

I did upload an image at http://www.tinypic.com. Do you want me to re-upload it?

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127562

Imagine an image with 4 objects, how to add an additional object in the image? That was my question. I uploaded an image with 4 objects at http://www.tinypic.com.

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127601

What about now?

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127605

And exactly how am I supposed to find your images? tinypic.com is a big web site.

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127620

Where can I send you the image?

Image Analyst
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127643

You don't need to send it. Just tell me its URL so we can find it.

Cesar
on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/62225#comment_127654

- © 1994-2015 The MathWorks, Inc.
- Site Help
- Patents
- Trademarks
- Privacy Policy
- Preventing Piracy
- Terms of Use
- RSS
- Google+

- Featured MathWorks.com Topics:
- New Products
- Support
- Documentation
- Training
- Webinars
- Newsletters
- MATLAB Trials
- Careers

## 2 Comments

## Youssef Khmou (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62225#comment_127624

Hi Cesar, you have to specify your problem, give an example with per example "circuit.tif" so everyone can work on it instead of image taken from web .

## Cesar (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62225#comment_127640

By example consider an image with 4 birds (bird.tif), and I want to add of of those birds to the same image which now has 5 birds. Let me know if that is clear.