如何在MATLAB中创建拼贴?

时间:2010-08-15 12:48:55

标签: image matlab image-processing

我想编写一个程序,可以从给定的图片文件夹创建随机拼贴。

首先,我想从三张图片中创建一个简单的拼贴画。像这样:

alt text

我现在几乎没有代码

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 

如何在MATLAB中完成?


如何拉伸旋转,然后将各个图像放在画布上,以便在创建拼贴时能够完全自由?可能会出现图像放置,使图像位于画布区域之外。

alt text

将图像拉伸到形状是拼贴是一种方式,但我希望能够拉伸和放置它们

1 个答案:

答案 0 :(得分:3)

假设您想要将图像拉伸成形状并且拥有图像处理工具箱,您可以使用IMRESIZE以下列方式进行拼贴:

创建一个保存为.m文件的函数。这比调用全部清除/全部关闭

更安全
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)