How to make summation of moved and fixed matrix ?
Afficher commentaires plus anciens
I would like to calculate the summation of moved and fixed matrix.
The purpose is to join two image without the spaces(zeros) between.
TEMP is the matrix and DATA is the moved matrix by LengthofZero.
To calculate the summation of different sizes matrix, I made the zeros to make the same size as below.
The below is the code I made, but I think there is more efficient ways available in Matlab.
Please help me please.
load('A1.mat')
load('A2.mat')
figure(1)
imshowpair(A1,A2,'montage')
TEMP = A1; DATA = A2;
LengthofZero = 251;
% Move the data in the column direction by LengthofZero and summation of DATA & TEMP
[m1,n1] = size(TEMP);
[m2,n2] = size(DATA);
TEMP = [TEMP,zeros(m2,n2)];
DATA = [zeros(m1,n1),DATA];
DATA = circshift(DATA,-LengthofZero,2);
TEMP = TEMP + DATA;
figure(2)
imshow(TEMP,[])
Réponse acceptée
Plus de réponses (1)
Simon Chan
le 4 Fév 2022
Not sure it is efficient or not, just an optional way of doing it:
load('A1.mat');
load('A2.mat');
s1 = regionprops(bwareafilt(~A1,2),'BoundingBox'); % Use complement image and remove the smallest object
bbox1 = cat(1,s1.BoundingBox); % Find the bounding boxes coordinates
B1 = A1(:,1:floor(max(bbox1(:,1)))); % First image get the largest starting point of the Bounding Box
s2 = regionprops(bwareafilt(~A2,2),'BoundingBox');
bbox2 = cat(1,s2.BoundingBox);
B2 = A2(:,ceil(min(bbox2(:,1)+bbox2(:,3))):end); % Second image get the smallest ending point of the Bounding Box
B = [B1,B2]; % Combine them
imshow(B,[])

1 commentaire
Smithy
le 4 Fév 2022
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
