changing a matrix size
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
abdelillah douhi
am 6 Sep. 2019
Kommentiert: Steven Lord
am 6 Sep. 2019
Hello,
Basically i want to change a logical matrix size from 144x144 to 512x512, here is the case that i have:
i have two images of the same object with those sizes accordingly with some region of interest approximately in the middle of the 144 image here is a small example:
the matrix of the region is as follows:
[0000000000
0001111000
0000110000
0000000000]
the regions are hazardous but in the middle give or take, i have them all. now i want to apply those regions to the bigger image so i need to expande the matrix to go with the 512x512 image. as follows
[000000000000000000000
000000111111110000000
000000001111000000000
000000000000000000000]
any ideas ?
Regards
4 Kommentare
Steven Lord
am 6 Sep. 2019
I hope you do get the idea now
No, I don't. There are many different ways you could expand a 144-by-144 matrix to be a 512-by-512 matrix. I asked what method you want to use. To make this a bit more concrete, using my 4-by-4 example above:
smallPattern = [0 0 0 1; 0 1 1 0; 0 0 1 0; 1 0 0 0]
Should it be expanded to 10-by-10 by padding?
larger = zeros(10);
% Pad along the bottom and right
largePattern1 = larger; largePattern1(1:4, 1:4) = smallPattern
% Pad along the top and right
largePattern2 = larger; largePattern2(7:10, 1:4) = smallPattern
% Pad on all four sides
largePattern3 = larger; largePattern3(4:7, 4:7) = smallPattern
Should we replicate the rows and columns?
% Each element is roughly equal in size, extra rows go to the
% left and top sections
largePattern4 = repelem(smallPattern, [3 2 3 2], [3 2 3 2])
% Shows some symmetry
largePattern5 = repelem(smallPattern, [2 3 3 2], [3 2 2 3])
Should we replicate the matrix as a whole then trim off the extra pieces?
twelve = repmat(smallPattern, 3);
% Trim the bottom and right
largePattern6 = twelve(1:10, 1:10)
% Trim the border on all four sides
largePattern7 = twelve(2:11, 2:11)
% Trim the top and left
largePattern8 = twelve(3:12, 3:12)
Each of those eight larger patterns is a different matrix, built in some way from the small pattern, and all are 10-by-10.
Akzeptierte Antwort
Bruno Luong
am 6 Sep. 2019
Bearbeitet: Bruno Luong
am 6 Sep. 2019
% A is 144 x 144 input binary matrix
I512 = logical(interp2(...
linspace(0,1,size(A,2)),...
linspace(0,1,size(A,1)),...
double(A),...
linspace(0,1,512),...
linspace(0,1,512)')); % this is the "same" image with size 512 x 512
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!