Matrix manipulation problem under MATLAB
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hello
I have a treatment done on a single pixel I want to redo it on the whole image of tail 95 * 95
load('end3.mat')
d=size(A);
[carte] =hyperConvert3d(A,sqrt(d(2)), sqrt(d(2)),d(1));
P1=carte(:,:,1);
P2=carte(:,:,2);
P3=carte(:,:,3);
C1=round(P1*9);
C2=round(P2*9);
C3=round(P3*9);
i = input('Donner le numero de ligne');
j = input('Donner le numero de colone');
A=hyperImage123(3,C1(i,j),C2(i,j),C3(i,j));
B=hyperImage123(3,C1(i-1,j-1),C2(i-1,j-1),C3(i-1,j-1));
C=hyperImage123(3,C1(i-1,j),C2(i-1,j),C3(i-1,j));
D=hyperImage123(3,C1(i-1,j+1),C2(i-1,j+1),C3(i-1,j+1));
E=hyperImage123(3,C1(i,j-1),C2(i,j-1),C3(i,j-1));
F=hyperImage123(3,C1(i,j+1),C2(i,j+1),C3(i,j+1));
G=hyperImage123(3,C1(i+1,j-1),C2(i+1,j-1),C3(i+1,j-1));
H=hyperImage123(3,C1(i+1,j),C2(i+1,j),C3(i+1,j));
I=hyperImage123(3,C1(i+1,j+1),C2(i+1,j+1),C3(i+1,j+1));
Fenetre=zeros(9,9);
Fenetre(4:6,4:6)=A;
Fenetre(1:3,1:3)=B;
Fenetre(1:3,4:6)=C;
Fenetre(1:3,7:9)=D;
Fenetre(4:6,1:3)=E;
Fenetre(4:6,7:9)=F;
Fenetre(7:9,1:3)=G;
Fenetre(7:9,4:6)=H;
Fenetre(7:9,7:9)=H;
5 Comments
Walter Roberson
on 21 Nov 2018
what is hyperImage123?
dakhli mohamed
on 21 Nov 2018
dakhli mohamed
on 21 Nov 2018
Walter Roberson
on 21 Nov 2018
The last assignment to the window should be I not H.
Walter Roberson
on 21 Nov 2018
Edited: Walter Roberson
on 21 Nov 2018
note
Fenetre = [B, C, D;
E, A, F;
G, H, I]
No need for the subscripted assignments .
Answers (1)
Walter Roberson
on 21 Nov 2018
0 votes
Nested for loops .
7 Comments
dakhli mohamed
on 21 Nov 2018
Walter Roberson
on 21 Nov 2018
load('end3.mat')
d=size(A);
[carte] =hyperConvert3d(A,sqrt(d(2)), sqrt(d(2)),d(1));
P1=carte(:,:,1);
P2=carte(:,:,2);
P3=carte(:,:,3);
C1=round(P1*9);
C2=round(P2*9);
C3=round(P3*9);
nr = size(C1,1);
nc = size(C1,2);
Fenetre = cell(nr-2,nc-2);
for i = 2:nr-1
for j = 2:nc-1
A=hyperImage123(3,C1(i,j),C2(i,j),C3(i,j));
B=hyperImage123(3,C1(i-1,j-1),C2(i-1,j-1),C3(i-1,j-1));
C=hyperImage123(3,C1(i-1,j),C2(i-1,j),C3(i-1,j));
D=hyperImage123(3,C1(i-1,j+1),C2(i-1,j+1),C3(i-1,j+1));
E=hyperImage123(3,C1(i,j-1),C2(i,j-1),C3(i,j-1));
F=hyperImage123(3,C1(i,j+1),C2(i,j+1),C3(i,j+1));
G=hyperImage123(3,C1(i+1,j-1),C2(i+1,j-1),C3(i+1,j-1));
H=hyperImage123(3,C1(i+1,j),C2(i+1,j),C3(i+1,j));
I=hyperImage123(3,C1(i+1,j+1),C2(i+1,j+1),C3(i+1,j+1));
Fenetre{i-1,j-1} = [B, C, D;
E, A, F;
G, H, I]
end
end
Fenetre = cell2mat(Fenetre);
The result will not be 285 by 285. You are building 9 x 9 windows, and 285 is not divisible by 9.
dakhli mohamed
on 22 Nov 2018
Edited: dakhli mohamed
on 22 Nov 2018
Walter Roberson
on 22 Nov 2018
Your Fenetre code clearly takes a single pixel and converts it to 9 x 9. If it is the applicable code then your final result size would have to be divisible by 9. If it is not the applicable code then it is difficult to assist you as we do not know what (if any) part of it is relevant.
dakhli mohamed
on 22 Nov 2018
Walter Roberson
on 22 Nov 2018
Edited: Walter Roberson
on 22 Nov 2018
"my code takes a single pixel and converts it to 3 x 3"
No, it does not. It takes a single pixel and converts it to 9 x 9.
Look at your code: you input a scalar i and scalar j from the user, and you create
Fenetre=zeros(9,9);
from it, which is clearly 9 x 9.
dakhli mohamed
on 22 Nov 2018
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!