2010-08-15 55 views
2

我想寫一個程序,可以從給定的圖片文件夾創建隨機拼貼。如何在MATLAB中創建拼貼?

首先,我想從三個圖像創建一個簡單的拼貼畫。事情是這樣的:

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做到幾乎無碼?


我怎樣才能拉伸旋轉,然後放置在畫布上的各個圖像,這樣我可以有完全的自由,同時創造拼貼?圖像的位置可能發生在圖像位於畫布區域之外的位置。

拉伸圖片以構成是拼貼是一種方式,但我希望能夠伸展並把它們

+0

什麼大小的個別圖像?如果所有的圖像都是方形的呢? – Jonas 2010-08-15 14:12:58

+0

你有圖像處理工具箱嗎? – Jonas 2010-08-15 15:06:39

回答

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) 
+0

謝謝!是的,我可以使用工具箱。我希望能夠將圖像放置在畫布的任何部分。什麼是最好的方式來做到這一點? – Lazer 2010-08-15 17:52:58

+0

您首先定義每個圖像的中心點和新尺寸。然後(在一個循環中)調整圖像的大小,使用'imrotate'旋轉它們,最後將圖像放到拼貼畫上,以使中心位於您想要的位置。 – Jonas 2010-08-17 03:00:32