필터 지우기
필터 지우기

Combine Images to display on single page

조회 수: 4 (최근 30일)
Cg Gc
Cg Gc 2019년 1월 2일
댓글: Image Analyst 2019년 1월 9일
I have multiple sets of 21 images that I would like to display either as a single image or as on one page, which ever is easier. For simplicity I only uploaded 4 here.
I have tried the code below, but I received error messages.
fileFolder = fullfile(matlabroot,'toolbox','images','imdata');
dirOutput = dir(fullfile(fileFolder,'trajplot_*.png'));
fileNames = string({dirOutput.name});
montage(fileNames, 'Size', [2 2]);
Error using montage>getImagesFromFiles (line 366)
FILENAMES must be a cell array of strings or character vectors.
Error in montage>parse_inputs (line 243)
[I,cmap] = getImagesFromFiles(varargin{1});
Error in montage (line 114)
[I,cmap,mSize,indices,displayRange,parent] = parse_inputs(varargin{:});
img1 = imread('trajplot_C1_0012_10m.png');
img2 = imread('trajplot_C2_0012_10m.png');
img3 = imread('trajplot_C3_0012_10m.png');
img4 = imread('trajplot_C5_0012_10m.png');
>> multi = cat(3,img1,img2,img3);
>> montage(multi);
Error using images.internal.imageDisplayValidateParams>validateCData (line
115)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 241)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in montage (line 156)
hh = imshow(bigImage, displayRange,parentArgs{:});
>> multi = cat(4,img1,img2,img3,img4);
>> montage(multi);
%%The image shows up, but is one giant black square.%%
img1 = imread('trajplot_C1_0012_10m.jpeg');
img2 = imread('trajplot_C2_0012_10m.jpeg');
img3 = imread('trajplot_C3_0012_10m.jpeg');
>> multi = cat(3,img1,img2,img3);
montage(multi);
Error using images.internal.imageDisplayValidateParams>validateCData
(line 115)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 241)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in montage (line 156)
hh = imshow(bigImage, displayRange,parentArgs{:});
Does anyone know what is going on? Are my images in the wrong format or possibly too big?
The original files are in .ps format and were converted to .png using an online converter. If they need to be converted into something else, please let me know.

답변 (2개)

Image Analyst
Image Analyst 2019년 1월 2일
They appear, from the error message, to not be RGB images. Do they have an alpha plane or something?
What does this say?
whos img1
size(img1)
If it's not 3 planes, then you might take the first 3, if those represent R, G, and B.
img1 = img1(:,:,1:3);
or somehow otherwise process it until you get 3 planes. Attach two of your PNG files if you need more help.

Image Analyst
Image Analyst 2019년 1월 2일
Don't cat() them together into a 4-D array, just use montage():
multi = montage(img1,img2,img3,img4);
  댓글 수: 9
Cg Gc
Cg Gc 2019년 1월 8일
편집: Cg Gc 2019년 1월 9일
I finally upgraded to 2018b and the code works. Thank you!
Last questions. Can the images be in color? Do you know how to get rid of the huge border and make the images larger and less blurry? The border is at least 2 inches wide and makes printing the images a nightmare.
Image Analyst
Image Analyst 2019년 1월 9일
I think the alpha channel can only be gray scale, not RGB, so you're better off trying to get them saved in a normal way in the first place, rather than how they are now.
To get rid of the border, try thresholding and cropping after the montage has been made.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by