Matrix/Image Merging
Mostrar comentarios más antiguos
Hi,
I have 2 matrix A and B which are different size, I would like to combine them together with A as the master to make a new matrix with consist of A and B. The way I want both matrix is merge through a location on both matrix. For example place Matrix A on Matrix B on certain location, Eg ‘8’ on Matrix A to Matrix B’s ‘22’ to result Matrix Merge.
A=[1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15]
A =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
B=[13 14 15 20 27 21; 16 17 18 19 25 26; 21 22 23 24 25 23]
B =
13 14 15 20 27 21
16 17 18 19 25 26
21 22 23 24 25 23
Merge=[0 13 14 15 20 27 21 ; 1 2 3 4 5 25 26 ; 6 7 8 9 10 25 23 ; 11 12 13 14 15 0 0]
Merge =
0 13 14 15 20 27 21
1 2 3 4 5 25 26
6 7 8 9 10 25 23
11 12 13 14 15 0 0
Besides that, additional space will have value of 0. I'll use these method to merge 2 images where i have a location at both images which going to be used to control the location of merging.
Thanks;
1 comentario
Kyle
el 25 de Jun. de 2011
Respuesta aceptada
Más respuestas (2)
Matt Fig
el 24 de Jun. de 2011
Kyle, what to do when multiple matches are found in B, since your example B has duplicates?
%
%
%
%
%
EDIT In response to clarification about duplicates.
Since you say there will not be duplicates in the actual data, I will use example matrices without duplicates:
A = reshape(1:12,3,4);
B = reshape(1:30,5,6)+12;
NA = 5; % The number to overlap in A.
NB = 35; % The number to overlap in B.
[mA,nA] = size(A);
[mB,nB] = size(B);
[IA,JA] = find(A==NA);
[IB,JB] = find(B==NB);
mC = mA+mB+mod(mA+mB,2)+1;
nC = nA+nB+mod(nA+nB,2)+1;
C = zeros(mC,nC);
cC = round([mC/2,nC/2]);
C(cC(1)-IB+1:cC(1)-IB+mB,cC(2)-JB+1:cC(2)-JB+nB) = B;
C(cC(1)-IA+1:cC(1)-IA+mA,cC(2)-JA+1:cC(2)-JA+nA) = A;
C = C(:,any(logical(C)));
C = C(any(logical(C),2),:)
7 comentarios
Kyle
el 24 de Jun. de 2011
Matt Fig
el 24 de Jun. de 2011
But if there are two matches, then there is two ways to overlap. Which is preferred?
Kyle
el 24 de Jun. de 2011
Sean de Wolski
el 24 de Jun. de 2011
That would crop out black columns or rows of an image.
Matt Fig
el 24 de Jun. de 2011
True, but Kyle said there were no duplicates. In that case there shouldn't be an entire row or column that is the same!
Sean de Wolski
el 24 de Jun. de 2011
Good Point.
Kyle
el 25 de Jun. de 2011
Kyle
el 25 de Jun. de 2011
3 comentarios
Matt Fig
el 25 de Jun. de 2011
I don't have IMSHOW (I think that is an image processing toolbox function), but it works with:
image(C)
colormap(gray)
You will have to figure out what went wrong with IMSHOW, as I have no way to trouble-shoot.
Kyle
el 25 de Jun. de 2011
Kyle
el 28 de Jun. de 2011
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!