imtile does not work with cell array of images

11 次查看(过去 30 天)
Documentation for IMTILE says I can assign a cel array of images as an input variable.
This is instead what happens when I try to use it this way:
immag =
1×4 cell array
{1×1 Image} {1×1 Image} {1×1 Image} {1×1 Image}
>> otta=imtile(immag)
Error using images.internal.getImageFromFile (line 9)
The specified filename is not a string.
Thanks !
I add the whole tree of errors, it might be useful:
Error using images.internal.getImageFromFile (line 9)
The specified filename is not a string.
Error in images.internal.createMontage>getOneImage (line 339)
[I, map] = images.internal.getImageFromFile(imgSource{k});
Error in images.internal.createMontage>getImages (line 209)
img = getOneImage(imgSource,useIndexedRead, idxs(1), cmap);
Error in images.internal.createMontage (line 66)
imageArray = getImages( imgSrc, thumbnailSize, thumbnailInterp, ...
Error in imtile (line 9)
out = images.internal.createMontage(Isrc, thumbnailSize, thumbnailInterp, ...

回答(3 个)

Star Strider
Star Strider 2026-1-1
It seems obvious --
immag =
1×4 cell array
{1×1 Image} {1×1 Image} {1×1 Image} {1×1 Image}
>> otta=imtile(immag)
Error using images.internal.getImageFromFile (line 9)
The specified filename is not a string.
See the imtile documentation section on filenames for details. They have to be file names of the images, not the images themselves.
Perhaps you need to use the montage function instead.

Stephen23
Stephen23 2026-1-1
编辑:Stephen23 2026-1-1
"imtile does not work with cell array of images"
Yes, it does:
C = {rand(2,4,3),rand(2,4,3)};
I = imtile(C);
image(I)
The documentation here:
clearly states that it accepts a cell array of numeric images. My example above shows that this works exactly as documented. Your code does not work because you provided a cell array containing some kind of special class, which are clearly not numeric arrays.

DGM
DGM 2026-1-1
编辑:DGM 2026-1-1
You're feeding montage()/imtile() a cell array of graphics objects, not raster image arrays or filenames. I'm going to use montage() for this demonstration for simplicity, but the input handling is the same.
% these are filenames
fnameA = 'peppers.png';
fnameB = 'cameraman.tif';
% these are raster images (numeric arrays)
A = imread(fnameA);
B = imread(fnameB);
% these are graphics objects of type matlab.graphics.primitive.Image
objA = imshow(A); figure;
objB = imshow(B);
% montage()/imtile() work with filename inputs
figure;
montage({fnameA,fnameB})
% ... or with raster arrays
figure;
montage({A,B})
% but they do not accept graphics objects
figure;
montage({objA,objB})
Error using images.internal.getImageFromFile (line 9)
The specified filename is not a string.

Error in images.internal.createMontage>getOneImage (line 340)
[I, map] = images.internal.getImageFromFile(imgSource{k});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in images.internal.createMontage>getImages (line 210)
img = getOneImage(imgSource,useIndexedRead, idxs(1), cmap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in images.internal.createMontage (line 66)
imageArray = getImages( imgSrc, thumbnailSize, thumbnailInterp, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in montage (line 11)
[bigImage, cmap] = images.internal.createMontage( Isrc, thumbnailSize, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You either need to extract the raster data from the objects, or better yet just use the original data instead.
% or something
montage({objA.CData,objB.CData})

类别

Help CenterFile Exchange 中查找有关 Modify Image Colors 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by