Jay
Jay

Reputation: 199

combining the arrays

I have written a code and i'm pretty much stuck. In the following code, i have split the complete image into a 3*3 block. Each of the child (1-8) you can see, say i alter them in that child(1-8) array only. Is there a method to combine these array (mother & child 1-8) to get the complete image back with the alteration that i've already made

pd_x=imread(name_doc);
[pd_m,pd_n]=size(pd_x);
di_m=pd_m;
di_n=pd_n;

pd_rv=ceil(pd_m/3);
pd_cv=ceil(pd_n/3);

mother1=pd_x(1:pd_rv,1:pd_cv);
child1=pd_x(1:pd_rv,pd_cv:(pd_cv+pd_cv));
child2=pd_x(1:pd_rv,(pd_cv+pd_cv):pd_n);

child3=pd_x(pd_rv:(pd_rv+pd_rv),1:pd_cv);
child4=pd_x(pd_rv:(pd_rv+pd_rv),pd_cv:(pd_cv+pd_cv));
child5=pd_x(pd_rv:(pd_rv+pd_rv),(pd_cv+pd_cv):pd_n);

child6=pd_x((pd_rv+pd_rv):pd_m,1:pd_cv);
child7=pd_x((pd_rv+pd_rv):pd_m,pd_cv:(pd_cv+pd_cv));
child8=pd_x((pd_rv+pd_rv):pd_m,(pd_cv+pd_cv):pd_n);

Upvotes: 1

Views: 104

Answers (2)

Castilho
Castilho

Reputation: 3187

If you used the method I've posted on this answer and still has the 4d matrix created, just do this:

mother1 = permute( mat4d, [ 1 3 2 4 ] );
mother1 = reshape( mother1, [ pd_rv pd_cv ] );

But pd_rv and pd_cv should be calculated with floor, and not with ceil, shouldn't they?

Upvotes: 1

MrJames
MrJames

Reputation: 686

The syntax for concatenation is the following:

A = [12 62 93 -8 22; 16 2 87 43 91; -4 17 -72 95 6]
A =
    12    62    93    -8    22
    16     2    87    43    91
    -4    17   -72    95     6

Taken from http://www.mathworks.com/help/techdoc/math/f1-84864.html

I've also made a basic example, defining first v,v2 and v3:

>> v

v =

     1     2

>> v2

v2 =

     3     4

>> v3

v3 =

     5     6

I do the following concatenation, the result will be...

>> m = [v v2 v3; v3 v2 v];
>> m

m =

     1     2     3     4     5     6
     5     6     3     4     1     2

Hope it helps you understand how it works!!

Upvotes: 1

Related Questions