Creating a symmetric tile mosaic

2 views (last 30 days)
Giovani Pasini
Giovani Pasini on 25 Oct 2020
Answered: DGM on 19 Aug 2024
I'm trying to generate a tiled mosaic with some type of symmetric pattern but most of the info a found online is to create a chessboard or a matrix and not realy an image. The general idea is based on this image, the most important part is the color pattern and not the shape btw. Thanks for the help! :)

Answers (1)

DGM
DGM on 19 Aug 2024
I'm not really sure what the question was. "the color pattern but not the shape" really doesn't make much sense, since shapes in images are arguably just color patterns.
So we have two interpretations:
  1. How do I generate a symmetric pattern? (i.e. the tile)
  2. How do I generate a montage of images? (i.e. the mosaic)
The first task is probably something easier done in an actual graphics editing program. I'm going to ignore that for now. Creating the mosaic from similar-sized tiles is simple. Consider the repeated tiling of a single image:
The simplest way would be to just replicate the image. There's no border between tiles.
unzip pats.zip % for the forum
% inputs
inpict = imread('pat9.png');
tiling = [2 3];
% replicate
outpict = repmat(inpict,tiling);
imshow(outpict)
You could add a border between the tiles if you use imtile().
% inputs
inpict = imread('pat9.png');
tiling = [2 3];
bwidth = 5;
bcolor = [0.9173 0.8899 0.775];
% simple tiling with inconsistent border width
outpict = imtile(repmat(inpict,[1 1 1 prod(tiling)]),'gridsize',tiling, ...
'bordersize',bwidth,'backgroundcolor',bcolor);
imshow(outpict)
Note that the border is 5px around each tile. That means that the border between adjacent tiles is twice as wide as the border around the entire mosaic. You can fix that by adding an extra border on the result.
% inputs
inpict = imread('pat9.png');
tiling = [2 3];
bwidth = 5;
bcolor = [0.9173 0.8899 0.775];
% tiling with inconsistent border width
tiledpict = imtile(repmat({inpict},[prod(tiling) 1]),'gridsize',tiling, ...
'bordersize',bwidth,'backgroundcolor',bcolor);
% add extra border on the outside to make it consistent
for c = 1:size(tiledpict,3)
outpict(:,:,c) = padarray(tiledpict(:,:,c),[1 1]*bwidth,'replicate','both');
end
imshow(outpict)
That's clumsy and could be simplified with MIMT tools.
% inputs
inpict = imread('pat9.png');
tiling = [2 3];
bwidth = 5;
bcolor = [0.9173 0.8899 0.775];
% do everything with MIMT tools instead
outpict = addborder(inpict,bwidth,bcolor,'normalized');
outpict = imtile(repmat(outpict,[1 1 1 prod(tiling)]),tiling); % MIMT-only!
outpict = addborder(outpict,bwidth,bcolor,'normalized');
imshow(outpict)
Consider how we might extend this to recreating the original mosaic from multiple different tiles.
% inputs
instack = mimread('pat*.png'); % MIMT only
tiling = [3 3];
bwidth = 5;
bcolor = [0.9173 0.8899 0.775];
% do everything with MIMT tools
instack = imstacker(instack,'padding',bcolor);
instack = addborder(instack,bwidth,bcolor,'normalized');
outpict = imtile(instack,tiling); % MIMT-only!
outpict = addborder(outpict,bwidth,bcolor,'normalized');
imshow(outpict)
These last two examples rely on MIMT imtile(), which is a reversible 4D image reshaping tool, and not the same as imtile(), which is an extension of the display tool montage(). They are similar, but incompatible.
It should be noted that the original tiles given are not strictly symmetric. The angular spacing of features is not consistent, nor are the sequences of features colocated on a common center of symmetry. These were probably generated by hand.
That said, I did go ahead and clean up all the original tiles and denoise them as best I could. They have been trimmed, padded and resized to a consistent geometry. See the attached zip file.

Community Treasure Hunt

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

Start Hunting!