MATLAB Answers

How to create an image puzzle?

조회 수: 76(최근 30일)
Zurez 14 Apr 2013
편집: mohamad k 28 Jun 2018
I have to take an image and break it into 8 different blocks and then reshuffle it. Then the whole reshuffled image should become a part of 3*3 square blocks with one one block empty so as to create an image puzzle. Please guide me . I am using Matlab 2009b

  댓글 수: 0

로그인 to comment.

채택된 답변

Knut 14 Apr 2013
편집: Knut 14 Apr 2013
I was not entirely sure what you were requesting, so I choose to do some interpretation. The snip below will load a standard image, divide it into a 3x3 grid, randomly sort those tiles, set one tile to zero, then assemble a "puzzle" image.
You could probably do this neater using image processing toolbox (blkproc), but I don't have that.
%%load and crop image
imdata = imread('ngc6543a.jpg');
new_dims = size(imdata) - rem(size(imdata), 3);
imdata = imdata(1:new_dims(1),1:new_dims(2), :);
%%Arrange into 3x3 cell
block_dims = new_dims./[3 3 1];
blocks = mat2cell(imdata, block_dims(1)*ones(3,1), block_dims(2)*ones(3,1), block_dims(3));
%%Rearrange randomly
blocks(1:9) = blocks(randperm(9));
%%Set one block to zero
blocks(ceil(9*rand(1))) = {zeros(block_dims, class(imdata))};
%%Return to image
puzzle = cell2mat(blocks);
%%Plot input and output
Edit: Removed an error spotted by Zurez

  댓글 수: 9

표시 이전 댓글 수: 6
Zurez 15 Apr 2013
Mark , that creat is a separate function. And my project was to create an image puzzle and develop and algorithm to solve that puzzle. I am still working on it ..
Harshit 15 Apr 2013
mohamad k
mohamad k 28 Jun 2018
hi guys, I have a project like this and the answer is appropriate but in addition I need to displace the blocks in the project. could you help me how to displace two blocks by clicking on them? thanks

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by