Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Image growth?

Subject: Image growth?

From: Aron Sceidt

Date: 1 Dec, 2010 16:30:27

Message: 1 of 4

How can I make an area around a binary image grow to a particular size?

For example if I have a rectangle r extracted from image A given by:

[x1, x2, xwidth, ywidth]

How can I make an image B the original size of A however only containing the area of r from the original image A and the rest being all black pixels?

Subject: Image growth?

From: ImageAnalyst

Date: 1 Dec, 2010 18:50:50

Message: 2 of 4

On Dec 1, 11:30 am, "Aron Sceidt" <sigarr...@gmail.com> wrote:
> How can I make an area around a binary image grow to a particular size?
>
> For example if I have a rectangle r extracted from image A given by:
>
> [x1, x2, xwidth, ywidth]
>
> How can I make an image B the original size of A however only containing the area of r from the original image A and the rest being all black pixels?

----------------------------------------------------------
Aron:
For the first question, use imdilate() to grow (enlarge) the "white"
part of a binary image, assuming you meant "binary" as in the most
common way people in image processing use it.
For the second question (not sure how this is an example of your first
question though), I can't tell what you're talking about. If you want
to make B (a sub-image of A inside rectangle "r") the same size as the
larger, original matrix A, you can use imresize(). If you want to
expand the canvas size around an image by padding it with zeros, use
padarray().

So, basically I didn't understand what you asked and you should look
up the three functions I suggested and see which one(s) meets your
needs.
-ImageAnalyst

Subject: Image growth?

From: Aron Sceidt

Date: 1 Dec, 2010 19:16:06

Message: 3 of 4

First of all my apologies for not making myself clear and thanks for your reply

all I really want is that if i have a rectangle extracted from an image at location (x1, y1, xwidth, ywidth), i want to get a new image the same size of the original image with the rectangle extracted from the original image placed at the same place it originally was and the remaining pixels put to black.

Optionally you can look at my problem as painting the area outside the selected rectangle black.

In the meantime i'm looking up the functions you suggested


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <d59cab3d-f064-4a87-9652-10eccf89a04a@y3g2000vbm.googlegroups.com>...
> On Dec 1, 11:30 am, "Aron Sceidt" <sigarr...@gmail.com> wrote:
> > How can I make an area around a binary image grow to a particular size?
> >
> > For example if I have a rectangle r extracted from image A given by:
> >
> > [x1, x2, xwidth, ywidth]
> >
> > How can I make an image B the original size of A however only containing the area of r from the original image A and the rest being all black pixels?
>
> ----------------------------------------------------------
> Aron:
> For the first question, use imdilate() to grow (enlarge) the "white"
> part of a binary image, assuming you meant "binary" as in the most
> common way people in image processing use it.
> For the second question (not sure how this is an example of your first
> question though), I can't tell what you're talking about. If you want
> to make B (a sub-image of A inside rectangle "r") the same size as the
> larger, original matrix A, you can use imresize(). If you want to
> expand the canvas size around an image by padding it with zeros, use
> padarray().
>
> So, basically I didn't understand what you asked and you should look
> up the three functions I suggested and see which one(s) meets your
> needs.
> -ImageAnalyst

Subject: Image growth?

From: ImageAnalyst

Date: 1 Dec, 2010 21:00:56

Message: 4 of 4

Just mask it out, like in this demo:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010b\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Set rectangle.
x1 = 80;
y1 = 35;
width = 95;
height = 75;
outputImage = grayImage; % Initialize
% Zero out the edges (margins).
% Zero top
outputImage(1:y1-1, :) = 0;
% Zero bottom
outputImage(y1+height:end, :) = 0;
% Zero left.
outputImage(y1:y1+height-1, 1:x1-1) = 0;
% Zero right.
outputImage(y1:y1+height-1, x1+width:end) = 0;
% Display the original gray scale image.
subplot(1, 2, 2);
imshow(outputImage, []);
title('Masked Image', 'FontSize', fontSize);

Tags for this Thread

No tags are associated with this thread.

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.

Contact us