why this command: a([],[],:)=A doesn't work? I try not to use for command

UPDATED: Finally I used bsxfun
---
%I is a 512*512 picture
outImg=uint8(zeros(512,512,3));
tempImg=I(:,:,1:3);
a=1;b=1;
for i=1:iTimes
temp=tempImg;
ax=mod((a*b+1)*((1:512)-1)-b*((1:512)-1),512)+1;
ay=mod(-a*((1:512)-1)+((1:512)-1),512)+1 ;
outImg(ax,ay,1:3)=temp; %this command does't work why ?
tempImg=outImg;
end
outImg=tempImg;
figure
imshow(outImg);
when I debugged, I found outImg was still zeros.
But the following command works.
A=zeros(2,2,3);
A(1,1,1)=6;
A(2,1,2)=6;
A(2,2,3)=6;
E=zeros(2,2,3);
E([1 2],[2 1],:)=A
A(:,:,1) =
6 0
0 0
A(:,:,2) =
0 0
6 0
A(:,:,3) =
0 0
0 6
E(:,:,1) =
0 6
0 0
E(:,:,2) =
0 0
0 6
E(:,:,3) =
0 0
6 0
I want to avoid using "for" command
for i=1:iTimes
for u=1:iH
for v=1:iW
temp=tempImg(u,v,1:3);
%arnold transform
bx=mod((a*b+1)*(u-1)-b*(v-1),iW)+1;
by=mod(-a*(u-1)+(v-1),iW)+1 ;
% record address of pixels after transforming
% X_1(u,v)=(bx);
% X_2(u,v)=(by);
outImg(bx,by,1:3)=temp;
end
end
tempImg=outImg;
end
outImg=tempImg;

Answers (1)

As you have defined ax and ay, they are:
ax = 1:512;
and
ay = ones(1,512);
Just look at them to see that. This means that in
outImg(ax,ay,1:3)=temp;
you are attempting to stuff the entire image into the top row of outImg, and that won’t work. You need to rethink what you are trying to accomplish.

1 Comment

I want to avoid using "for" command
for i=1:iTimes
for u=1:iH
for v=1:iW
temp=tempImg(u,v,1:3);
%arnold transform
bx=mod((a*b+1)*(u-1)-b*(v-1),iW)+1;
by=mod(-a*(u-1)+(v-1),iW)+1 ;
% record address of pixels after transforming
% X_1(u,v)=(bx);
% X_2(u,v)=(by);
outImg(bx,by,1:3)=temp;
end
end
tempImg=outImg;
end
outImg=tempImg;
I found
(X_1(i,j),X_2(i,j))~=(ax(i),ay(j))

This question is closed.

Tags

Asked:

on 5 Jun 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!