changing a matrix size

3 views (last 30 days)
abdelillah douhi
abdelillah douhi on 6 Sep 2019
Commented: Steven Lord on 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 Comments
Bruno Luong
Bruno Luong on 6 Sep 2019
What you plot are not logical matrix.
Steven Lord
Steven Lord on 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.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 6 Sep 2019
Edited: Bruno Luong on 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 Comments
abdelillah douhi
abdelillah douhi on 6 Sep 2019
Edited: abdelillah douhi on 6 Sep 2019
thanks for your answer but in fact the matrix of the roi ( the cercle) is logical, or else my program wont work, i tryed your solution it did solve the problem on the image but the outcom of the program didn't give exactly the values that i wanted didn't give any actualy.
abdelillah douhi
abdelillah douhi on 6 Sep 2019
thank you very much

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!