shuffle image of tiles

4 views (last 30 days)
dylan
dylan on 27 Oct 2013
Edited: DGM on 27 Mar 2022
Hi iam new to matlab, I have to write a function that will take in a image of any size, display it in square tiles and shuffles the squares around then show the new image

Answers (1)

DGM
DGM on 4 Feb 2022
I know this is probably homework and there's no point in answering it, but it's a boring Friday.
The typical approach is probably to detile the image using mat2cell() and then randomly permute the cell array and then retile with cell2mat(). That's succinct and works so long as your image geometry is already integer-divisible by the number of tiles.
If you just want something that works out of the box with any image, MIMT shuffle() works fine.
inpict = imread('peppers.png');
% note that [384 512] is not integer-divisible by [10 10]
tiling = [10 10];
outpict = shuffle(inpict,tiling); % output image is same size as inpict
imshow(outpict)
Default behavior is random permutation, but it can accept specified permutations as well.
  2 Comments
Samia Nushrat
Samia Nushrat on 26 Mar 2022
Error using imtile>parse_inputs (line 242)
Expected input number 3, PARAM, to match one of these values:
'GridSize', 'Frames', 'ThumbnailSize', 'BorderSize', 'BackgroundColor'
The input, 'direction', did not match any of the valid values.
Error in imtile (line 151)
parse_inputs(varargin{:});
Error in shuffle (line 103)
outpict(:,:,:,f) = imtile(thisframe,tiles,'direction','col');
Error in Shuffle_mm (line 4)
outpict = shuffle(inpict,tiling); % output image is same size as inpict
Getting these errors, help please.
DGM
DGM on 27 Mar 2022
Edited: DGM on 27 Mar 2022
The above example does not refer to the IPT function called imtile(). The two are completely different. IPT imtile() is more like montage(). MIMT imtile() and imdetile() are manipulation tools for 4D image arrays.
Since you're able to run other MIMT tools, I can only assume that MIMT has lower precedence in the path ordering than IPT does. You should be able to verify this by checking:
which imtile -all
You might ask why MIMT has a function with a name that conflicts with IPT. The answer is that it wasn't a conflict when I wrote it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!