Matrix manipulation problem under MATLAB

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

what is hyperImage123?
it's a function that fills a matrix with random values
This is a function " hyperImage123"
function matrice = hyperImage(dim, n1 ,n2 ,n3)
assert(n1 + n2 + n3 == dim^2, 'the count of elements must match the size of the matrix');
filler = repelem([1 2 3], [n1 n2 n3]);
matrice = reshape(filler(randperm(numel(filler))), dim, dim);
end
The last assignment to the window should be I not H.
note
Fenetre = [B, C, D;
E, A, F;
G, H, I]
No need for the subscripted assignments .

Answers (1)

Nested for loops .

7 Comments

I want to go through the whole image with this principle
it does not work because I do not have a good background in matlab it broke my head
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);
Fenetre=zeros(285,285);
for i=1:1 %i=1:95
for j=1:1 %j=1:95
A=hyperImage123(3,C1(i,j),C2(i,j),C3(i,j));
Fenetre(1:3,1:3)=A;
end
end
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.
I want it to be divisible by 3 ====> 95 * 3 (the size of the image each matrix of 3 * 3 takes a place in the final matrix (285 * 285)
the size of the matrix end3.mat is of size 95 * 95 after the clasificastion I get 3 class C1, C2, C3 each pixel is a matrix of 3 * 3 I want to put the result in a matrix of 285 * 285
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.
9 * 9 it's a pixel and its neighbors each pixel is 3 * 3
I worked at the beginning on a single pixel and his 4 voinsins now I want to apply the algorithm on the whole picture
my code takes a single pixel and converts it to 3 x 3.and the others are the neighbors of 4 face big I want to take a picture of 95 * 95 and and every pixel I want to convert it on 3 * 3 and the final goal it's to find a super resolution image
"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.
attached an example,p.jpg
A=hyperImage123(3,C1(i,j),C2(i,j),C3(i,j)); % central pixel
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));

This question is closed.

Asked:

on 21 Nov 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!