Combine Images to display on single page

11 ビュー (過去 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.
  1 件のコメント
Cg Gc
Cg Gc 2019 年 1 月 2 日
Name Size Bytes Class Attributes
img1 2275x1758x3 11998350 uint8
ans =
2275 1758 3

サインインしてコメントする。


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 Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by