필터 지우기
필터 지우기

Variable Number of images as inputs and superimpose together? - Homework

조회 수: 1 (최근 30일)
Nora
Nora 2013년 11월 19일
댓글: Nora 2013년 11월 19일
I am trying to make a function that will receive a variable number of image files. The function will read all the images and superimpose all images with equal contribution from each. So the input images might be different sizes, so the function needs to resize all images to the same size as the smallest image before superimposing.
This is the function I have so far, but it needs a lot more work.
function SuperImpose( varargin )
% INPUT VARIABLE NUMBER OF IMAGES AND USE imlincomb TO COMBINE THEM
% 17-NOV-2013, NM
cn = 0;
for i = 1:nargin
cn = imresize(varargin{i}, [384 512]);
cn = cn + 1;
cs{cn} = str;
end
sumim = imlincomb(cn);
imshow(sumim);
end

채택된 답변

Image Analyst
Image Analyst 2013년 11월 19일
편집: Image Analyst 2013년 11월 19일
You need two loops. One to read in all the images and see what sizes they are and to store the size of the smallest. Then another one where you read them all in and resize them according to the smallest, and sum them. Something like this (untested):
smallestRows = inf;
smallestColumns = inf;
for i = 1:nargin
thisImage = imread(varargin{i});
[rows, columns, numberOfColorChannels] = size(thisImage);
if rows < smallestRows
smallestRows = rows;
end
if columns< smallestColumns
smallestColumns= columns;
end
end
theSum = zeros(smallestRows, smallestColumns, numberOfColorChannels);
for i = 1:nargin
thisImage = imread(varargin{i});
theSum = theSum + double(imresize(thisImage, [smallestRows, smallestColumns]));
end
imshow(theSum, []);
To make it more robust, check to make sure that all images have the same number of color channels, and if they don't convert the gray scale images to color before summing.
  댓글 수: 4
Nora
Nora 2013년 11월 19일
I see! The reason I ask is because I got this error:
Where is this coming from?
EDU>> SuperImpose('lighthouse.jpg','Tulips.jpg','Desert.jpg')
Undefined function 'resize' for input arguments of type 'uint8'.
Error in SuperImpose (line 33)
theSum = theSum + double(resize(thisImage, [smallestRows, smallestColumns]));
Nora
Nora 2013년 11월 19일
I changed resize to imresize. Now I get a single blank image. Can you think of anything that would cause this?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 19일
I would suggest that instead of using varargin, that you pass a cell array containing the data.
Are you being passed the matrices of image data, or the file names ?
  댓글 수: 1
Nora
Nora 2013년 11월 19일
An example of calling the function is this:
>> im=SuperImpose('lighthouse.jpg','Tulips.jpg','Desert.jpg');
>>imshow(im);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by