Code not working. I need to move the image blocks by swapping cell's position inside the main image matrix. Help?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clc;clear;close all;warning off;
imdata = imread('check.jpg');
new_dims = size(imdata) - rem(size(imdata), 3);
imdata = imdata(1:new_dims(1),1:new_dims(2), :);
figure(1)
image(imdata)
text(100,300,'You Have40 Secs To Solve it !','FontSize',14,'Color','y');
text(150,350,'Use Arrow Keys : ','FontSize',14,'Color','y');
text(295,400,'\uparrow','FontSize',20,'Color','y','FontWeight','Bold');
text(225,450,'\leftarrow \downarrow \rightarrow','FontSize',20,'Color','y','FontWeight','Bold');
pause(3)
%%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));
%blacking the 9th image first
blocks(9) = {zeros(block_dims, class(imdata))};
%%Rearrange randomly
blocks(1:9) = blocks(randperm(9));
%%Set one block to zero
%
%blocks(3) = {zeros(block_dims, class(imdata))};
%%Return to image
puzzle = cell2mat(blocks);
disp(blocks)
%%Plot input and output
figure(2)
subplot(2,1,1), image(puzzle), axis equal;
%subplot(2,1,2),implay(timer_examp()), axis equal;
%truesize
k=index(cell{blocks(9)})% i am just trying to index a cell
pause(3)
%* bold*timer_examp()
%play
tic
move = 0;k = ind(blocks(9))
while ~isequal(puzzle,[1:3;4:6;7:9])
move= move+1;
m=waitforbuttonpress;
key = get(gcf,'CurrentKey');
% only works for keyboardinput if m==0
; %if it doesn't works then try find (blocks==9)
if strcmp(key,'uparrow')
blocks{k}=blocks{k-1};
elseif strcmp(key,'leftarrow')&& (k>3)
blocks(k) =blocks(k-3);
elseif strcmp(key,'rightarrow')&&(k<3)
blocks(k)= blocks(k+3);
elseif strcmp(key,'downarrow')
blocks(k) = blocks(k+3);
else
blocks(k)
end
end
2 comentarios
Respuestas (1)
Walter Roberson
el 19 de Abr. de 2013
other_k = k - 1;
blocks([k other_k]) = blocks([other_k k]);
4 comentarios
Ver también
Categorías
Más información sobre Computer Vision with Simulink en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!