views:

75

answers:

2

I want to write a program that can create random collages from a given folder of pictures.

To begin, I want to create a simple collage from three images. Something like this:

alt text

I have almost no code right now

clc;
clear all;
close all;

a = imread('a.png');
b = imread('b.png');
c = imread('c.png');

% create a new image of size X x Y

% for a simple collage

% place a in the top half
% place b in the bottom left
% place c in the bottom right 

How can this be done in MATLAB?


How can I stretch, rotate and then place the individual images on a canvas, so that I can have the complete freedom while creating the collage? The image placement might so happen that the images lie outside the canvas area.

alt text

Stretching images to form is collage is one way, but I want to be able to stretch and place them

+1  A: 

Assuming you want to stretch images into shape and that you have the image processing toolbox, you can do the collage the following way, using IMRESIZE:

Create a function that you save as a .m file. This is much safer than calling clear all/close all

function collImg = collage 
%#COLLIMG creates a collage of three images called 'a.png' 'b.png' and 'c.png'
%#
%# OUTPUT collImg : collage image, with individual images arranged as [a;b,c]
%#

a = imread('a.png');
b = imread('b.png');
c = imread('c.png');

newImageSize = [512,512]; %# or anything else that is even

%# get the new sizes - this approach requires even image size
newSizeA = newImageSize./[2,1];
newSizeB = newImageSize./[2,2];
newSizeC = newImageSize./[2,2];

%# resize the images and stick together
%# place a in the top half
%# place b in the bottom left
%# place c in the bottom right 
collImg = [imresize(a,newSizeA);imresize(b,newSizeB),imresize(c,newSizeC)];

%# display the image
figure,imshow(collImg)
Jonas
@Jonas: Thanks! yes, I can use the toolbox. I want to be able to place the images at any part of the canvas. What is the best way to do that?
Lazer
You first define the center point and the new size of each image. Then (in a loop) you resize the images, use `imrotate` to rotate them, and finally you place the image onto the collage so that the center is where you'd want it to be.
Jonas
A: 

Without getting into the code, I can just offer this function up:

imrotate.m

http://www.mathworks.com/access/helpdesk/help/toolbox/images/imrotate.html

MatlabDoug