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:
Combining two images of different size

Subject: Combining two images of different size

From: Anusha

Date: 15 Mar, 2011 12:09:07

Message: 1 of 4

I have a small image1, say of size 50 x 50 and a bigger image2 of size 200 x 300. How do I place the small image1 at a particular position of (x,y) on the image2? The image2 is then supposed to take pixels values starting from the (x,y) position of the pixel values from image1. Its something like composite of the pixels value from image1 into image2 starting the composite values from (x,y).

Thanks in advance for any kind help.

Subject: Combining two images of different size

From: Steven_Lord

Date: 15 Mar, 2011 13:25:59

Message: 2 of 4



"Anusha " <anusha@cs.usm.my> wrote in message
news:ilnkt3$670$1@fred.mathworks.com...
> I have a small image1, say of size 50 x 50 and a bigger image2 of size 200
> x 300. How do I place the small image1 at a particular position of (x,y)
> on the image2? The image2 is then supposed to take pixels values starting
> from the (x,y) position of the pixel values from image1. Its something
> like composite of the pixels value from image1 into image2 starting the
> composite values from (x,y).
>
> Thanks in advance for any kind help.

If the images are the same data type and have the same number of dimensions,
fill in the appropriate section of the larger with the smaller using regular
indexed assignment.

x = 1:10;
x(2:4) = [23 -17 8.5];

If they are not, you could try calling IMAGE using the three-input syntax to
control where the smaller image is placed.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Combining two images of different size

From: ImageAnalyst

Date: 15 Mar, 2011 13:54:14

Message: 3 of 4

On Mar 15, 8:09 am, "Anusha " <anu...@cs.usm.my> wrote:
> I have a small image1, say of size 50 x 50 and a bigger image2 of size 200 x 300. How do I place the small image1 at a particular position of (x,y) on the image2? The image2 is then supposed to take pixels values starting from the (x,y) position of the pixel values from image1. Its something like composite of the pixels value from image1 into image2 starting the composite values from (x,y).
>
> Thanks in advance for any kind help.

---------------------------------------------------------------
I just responded to something like this an hour ago (http://
groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/
16d55773abf222b7/40d7f8fcc9e57525?hl=en#40d7f8fcc9e57525)
Basically it's like Steve said - just use regular assignment.

This demo should be rather self-explanatory.

% Make our Gaussian Filter.
g = fspecial('gaussian', 5)
% Generate a larger array of sample data.
m = zeros(10)
% For simplicity, let's assume g can fit inside m.
% Otherwise you'll have to do some clipping.
% Define where you want g to go in m.
leftEdge = 3;
topEdge = 2;
% Find the size of g so we know what elements to assign.
[gRows gCols] = size(g);
% Do the assignment
m(topEdge:topEdge+gRows-1, leftEdge:leftEdge+gCols-1) = g

You may also be interested in the Stitch application:
http://www.mathworks.com/matlabcentral/fileexchange/25797-stitch

Description

This utility can stitch or average two images together into a single
image. Brings up a GUI to allow use to select two images from
listboxes, select whether they want them stitched side-by-side, or
over-and-under, where to place smaller images in the event of size
mismatches (for example in the center or the upper left), and allows
them to rotate one or both images by 90 or 180 degrees. It can process
a single pair of images, or batch process a number of selected pairs.

Besides images, it can also process sound files of ".wav" format.
For .WAV format sound files, it can stitch them together (concatenate
them). It does not blend (average) two wav files together (in this
version).

This should work with much older versions of MATLAB (than R2009b), as
long as you have the Image Processing Toolbox.

Subject: Combining two images of different size

From: Anusha

Date: 16 Mar, 2011 01:56:04

Message: 4 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2facea8f-c4ee-4cfb-ab6b-baf45553be1b@q12g2000prb.googlegroups.com>...
> On Mar 15, 8:09 am, "Anusha " <anu...@cs.usm.my> wrote:
> > I have a small image1, say of size 50 x 50 and a bigger image2 of size 200 x 300. How do I place the small image1 at a particular position of (x,y) on the image2? The image2 is then supposed to take pixels values starting from the (x,y) position of the pixel values from image1. Its something like composite of the pixels value from image1 into image2 starting the composite values from (x,y).
> >
> > Thanks in advance for any kind help.
>
> ---------------------------------------------------------------
> I just responded to something like this an hour ago (http://
> groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/
> 16d55773abf222b7/40d7f8fcc9e57525?hl=en#40d7f8fcc9e57525)
> Basically it's like Steve said - just use regular assignment.
>
> This demo should be rather self-explanatory.
>
> % Make our Gaussian Filter.
> g = fspecial('gaussian', 5)
> % Generate a larger array of sample data.
> m = zeros(10)
> % For simplicity, let's assume g can fit inside m.
> % Otherwise you'll have to do some clipping.
> % Define where you want g to go in m.
> leftEdge = 3;
> topEdge = 2;
> % Find the size of g so we know what elements to assign.
> [gRows gCols] = size(g);
> % Do the assignment
> m(topEdge:topEdge+gRows-1, leftEdge:leftEdge+gCols-1) = g
>
> You may also be interested in the Stitch application:
> http://www.mathworks.com/matlabcentral/fileexchange/25797-stitch
>
> Description
>
> This utility can stitch or average two images together into a single
> image. Brings up a GUI to allow use to select two images from
> listboxes, select whether they want them stitched side-by-side, or
> over-and-under, where to place smaller images in the event of size
> mismatches (for example in the center or the upper left), and allows
> them to rotate one or both images by 90 or 180 degrees. It can process
> a single pair of images, or batch process a number of selected pairs.
>
> Besides images, it can also process sound files of ".wav" format.
> For .WAV format sound files, it can stitch them together (concatenate
> them). It does not blend (average) two wav files together (in this
> version).
>
> This should work with much older versions of MATLAB (than R2009b), as
> long as you have the Image Processing Toolbox.

Thank you for the tips. It works for my case. Was really helpful.

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