ron*_*oni 2 matlab image-processing montage
大家好我正在使用matlab的蒙太奇命令来显示图像.但是我遇到了一个问题.我使用的命令如下:
dirOutput = dir('C:\Users\DELL\Desktop\book chapter\Journal chan vese\robust
contour initialization\book for document\4 phase\*.jpg');
fileNames = {dirOutput.name}'
montage(fileNames, 'Size', [1 6]);
export_fig combined1.jpg -r300
Run Code Online (Sandbox Code Playgroud)
我有6张图片(所有灰度).但是,命令提示符立即抛出这样的错误:
//Error using montage>getImagesFromFiles (line 349)
//FILENAMES must contain images that are the same size.
//Error in montage>parse_inputs (line 225)
// [I,cmap] = getImagesFromFiles(varargin{1});
//Error in montage (line 112)
//[I,cmap,mSize,indices,displayRange] = parse_inputs(varargin{:});
//Error in montage_pics (line 3)
//montage(fileNames, 'Size', [1 6]);
Run Code Online (Sandbox Code Playgroud)
我甚至在这里上传了一些图片:



可以清楚地看到,所有图像都是灰度级的.然后我读了图像大小,它们如下:
1.128X128 2.128X128*3 3.128X128*3 4.128X128 5.128X128*3 6.128X128*3. 因此,一些图像被视为确实是彩色图像.
我的问题是如何使用蒙太奇命令这样的图像.另一个问题是蒙太奇命令总是需要相似大小的图像.所以我想避免这个漏洞.
当然,我可以使用软件工具将图像转换为所需的格式,但这是一种糟糕的工作方式.我相信下面的代码如果添加到我的原始代码将解决这个问题
%Read Each Image
I=imread('image');
I=imresize(I,[128 128]);
I=I(:,:,1);
%Apply montage command
Run Code Online (Sandbox Code Playgroud)
但是我无法将此代码集成到我的原始代码中.请帮我解决这个问题.在此先感谢各位宝贵的建议和帮助.
要蒙太奇,你必须确保
.
images={'eight.tif','fabric.png','football.jpg'};
%intended size
ssize=128;
%preallocation
IALL=zeros(ssize,ssize,1,numel(images));
for idx=1:numel(images)
%get image, ensure double to avoid issues with different colour depths
I=im2double(imread(images{idx}));
%resize
I=imresize(I,[ssize,ssize]);
%if rgb, change to gray
if size(I,3)>1 %rgb image
I=rgb2gray(I);
end
%insert
IALL(:,:,:,idx)=I;
end
montage(IALL);
Run Code Online (Sandbox Code Playgroud)