How to create an image puzzle?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
채택된 답변
Hi.
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
figure(1)
image(imdata)
figure(2)
image(puzzle)
Edit: Removed an error spotted by Zurez
댓글 수: 9
Yes you guessed it right , I am trying to make an image puzzle with user solving it using the arrow keys. Is there a limit on the dimension or file size of the image used? P.S : While using your code my Matlab R2012a is giving the following errors:
Error using index (line 2) Not enough input arguments. Error in image1 (line 9) blocks(index) = blocks(randperm(9));
Knut
2013년 4월 14일
If you want user interaction that is outside of my MATLAB competence. You might be able to use my script as a starting-point, and simple user-interaction using the input() function.
I am aware of no limits on image dimensions or file-size. I have tried to make it work with various rgb/mono and uint8/double image formats, but no guarantees. The image will be cropped to the nearest multiple of 3 in both dimensions.
Zurez
2013년 4월 14일
Knut, thank you so much for helping me out and spending your precious time for me . I am accepting this answer. I have more queries , but I will post them as a different question :) . Thanx again.
Mark
2013년 4월 14일
Excuse me..
I have a project, also image puzzle, here's my code, but the problem is the line "s=creat;" i don't know why is it like that. i'm using 7.9.0(R2009b)Matlab version. can you tell me how to fix it? thank you.
Mark
2013년 4월 14일
%%HELP : PUZZEL
% Use Arrow keys
% \uparrow
% \leftarrow \downarrow \rightarrow
% to move toward the empty
% space.
%%Init
clc;clear;close all;warning off;
im = imread('se.jpg');
im1 = imresize(im,[300 300]);
imshow(im1);
text(50,150,'You Have40 Secs To Solve it !','FontSize',12,'Color','y');
text(75,174.5,'Use Arrow Keys : ','FontSize',12,'Color','y');
text(147.5,200,'\uparrow','FontSize',20,'Color','y','FontWeight','Bold');
text(112.5,225,'\leftarrow \downarrow \rightarrow','FontSize',20,'Color','y','FontWeight','Bold');
pause(3)
res=1;
for i = 1:3
part1(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part4(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part7(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part2(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part5(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part8(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part3(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part6(:,:,i) = im1(1:200,1:200,i);
end
for i = 1:3
part9(:,:,i) = im1(1:200,1:200,i);
end
part9 = uint8(0.941*ones(200,200,3));
partf = {part1 part4 part7 part2 part5 part8 part3 part6 part9};
part = {part1 part4 part7 part2 part5 part8 part3 part6 part9};
part11 = cell(3,3);
s = creat;
for i = 1:9
ind = s(i);
part11(i) = part(ind);
end
part2 = part11;
img = cell2mat(part2);
imshow(img);
move = 0;
tic
%%PLAY
while ~isequal(s,[1:3;4:6;7:9])
move = move + 1;
k = waitforbuttonpress;
cc = get(gcf,'CurrentKey');
ind = find(s==9);
switch ind
case 1
if strcmp(cc,'uparrow')
s = swapmat(s,1,2);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,1,4);
else
s = s;
end
case 2
if strcmp(cc,'uparrow')
s = swapmat(s,2,3);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,2,5);
elseif strcmp(cc,'downarrow');
s = swapmat(s,2,1);
else
s = s;
end
case 3
if strcmp(cc,'downarrow')
s = swapmat(s,3,2);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,3,6);
else
s = s;
end
case 4
if strcmp(cc,'uparrow')
s = swapmat(s,4,5);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,4,7);
elseif strcmp(cc,'rightarrow');
s = swapmat(s,4,1);
else
s = s;
end
case 5
if strcmp(cc,'uparrow')
s = swapmat(s,5,6);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,5,8);
elseif strcmp(cc,'downarrow');
s = swapmat(s,5,4);
elseif strcmp(cc,'rightarrow')
s = swapmat(s,5,2);
else
s = s;
end
case 6
if strcmp(cc,'downarrow')
s = swapmat(s,6,5);
elseif strcmp(cc,'leftarrow')
s = swapmat(s,6,9);
elseif strcmp(cc,'rightarrow');
s = swapmat(s,6,3);
else
s = s;
end
case 7
if strcmp(cc,'uparrow')
s = swapmat(s,7,8);
elseif strcmp(cc,'rightarrow')
s = swapmat(s,7,4);
else
s = s;
end
case 8
if strcmp(cc,'downarrow')
s = swapmat(s,8,7);
elseif strcmp(cc,'uparrow')
s = swapmat(s,8,9);
elseif strcmp(cc,'rightarrow');
s = swapmat(s,8,5);
else
s = s;
end
case 9
if strcmp(cc,'downarrow')
s = swapmat(s,9,8);
elseif strcmp(cc,'rightarrow')
s = swapmat(s,9,6);
else
s = s;
end
end
for i = 1:9
ind = s(i);
part11(i) = part(ind);
end
part2 = part11;
img = cell2mat(part2);
imshow(img);
t = toc;
if t > 40
s = [1:3;4:6;7:9];
res = 0;
end
end
partf1 = cell(3,3); for i = 1:9 ind = s(i); partf1(i) = partf(ind); end img = cell2mat(partf1); imshow(img); if res == 0 text(180,300,'TIME OUT','FontSize',20,'Color','y'); else text(100,300,['TOTAL MOVES : ' num2str(move)],'FontSize',20,'Color','y'); end %% eof
Mark
2013년 4월 14일
or can i have a code for image puzzle?? because the project will be submitted tomorrow.. can you help me with this?
Zurez
2013년 4월 15일
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
2013년 4월 15일
See this an open source for all what you need http://www.cs.bgu.ac.il/~icvl/lab_projects/automatic-jigsaw-puzzle-solving/#Download
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
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Word games에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
