how can split image to 4 parts using "reshape" or using another way?

1 view (last 30 days)
how can split image to 4 parts using "reshape" or using another way?

Answers (2)

John D'Errico
John D'Errico on 21 Feb 2018
Why not try something? That is how you will learn.
A = rand(10,10)
A =
0.93614 0.13657 0.90563 0.5726 0.84819 0.67039 0.88059 0.60703 0.70625 0.51732
0.65876 0.21378 0.65182 0.38672 0.071682 0.4315 0.46093 0.053151 0.11428 0.21982
0.74794 0.21783 0.55094 0.085353 0.73923 0.34301 0.24875 0.59034 0.62061 0.38731
0.29529 0.14848 0.085495 0.3939 0.30351 0.61554 0.37059 0.26615 0.9813 0.66854
0.68423 0.6687 0.85758 0.058756 0.14468 0.0059446 0.68537 0.58939 0.36382 0.22756
0.20548 0.12054 0.5337 0.44348 0.47234 0.50325 0.32803 0.63827 0.94148 0.4208
0.77899 0.84029 0.53184 0.32736 0.021976 0.74268 0.80725 0.4474 0.28855 0.55414
0.56198 0.66423 0.093623 0.53036 0.25132 0.61766 0.95857 0.47626 0.57313 0.76301
0.42388 0.80682 0.17905 0.21329 0.42847 0.85672 0.24577 0.91463 0.32361 0.16648
0.046974 0.085508 0.73136 0.96149 0.5751 0.9539 0.51691 0.69254 0.99483 0.8542
permute(reshape(A,[10/2,2,10/2,2]),[1 3 2 4])
ans(:,:,1,1) =
0.93614 0.13657 0.90563 0.5726 0.84819
0.65876 0.21378 0.65182 0.38672 0.071682
0.74794 0.21783 0.55094 0.085353 0.73923
0.29529 0.14848 0.085495 0.3939 0.30351
0.68423 0.6687 0.85758 0.058756 0.14468
ans(:,:,2,1) =
0.20548 0.12054 0.5337 0.44348 0.47234
0.77899 0.84029 0.53184 0.32736 0.021976
0.56198 0.66423 0.093623 0.53036 0.25132
0.42388 0.80682 0.17905 0.21329 0.42847
0.046974 0.085508 0.73136 0.96149 0.5751
ans(:,:,1,2) =
0.67039 0.88059 0.60703 0.70625 0.51732
0.4315 0.46093 0.053151 0.11428 0.21982
0.34301 0.24875 0.59034 0.62061 0.38731
0.61554 0.37059 0.26615 0.9813 0.66854
0.0059446 0.68537 0.58939 0.36382 0.22756
ans(:,:,2,2) =
0.50325 0.32803 0.63827 0.94148 0.4208
0.74268 0.80725 0.4474 0.28855 0.55414
0.61766 0.95857 0.47626 0.57313 0.76301
0.85672 0.24577 0.91463 0.32361 0.16648
0.9539 0.51691 0.69254 0.99483 0.8542

Image Analyst
Image Analyst on 21 Feb 2018
How about indexing?
[rows, columns, numColorChannels] = size(yourImage);
middleRow = floor(rows/2);
middleCol = floop(columns/2);
upperLeftImage = yourImage(1:middleRow, 1:middleCol, :);
upperRightImage = yourImage(1:middleRow, middleCol+1:end, :);
lowerLeftImage = yourImage(middleRow+1:end, 1:middleCol, :);
lowerRightImage = yourImage(middleRow+1:end, middleCol+1:end, :);

Community Treasure Hunt

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

Start Hunting!