필터 지우기
필터 지우기

reshaping a 3D array

조회 수: 1 (최근 30일)
t4741
t4741 2019년 9월 7일
편집: Bruno Luong 2019년 9월 7일
I have a 3D stack of RGB values.
Colours( 1, 1, :) = a stack of values eg , 1 through 12 in the form R G B R G B R G B R G B.
I need to format it into three layers instead of 12, where each layer is the individual colour etc.
so it would be in the form
R R R (layer 1)
G G G (layer 2)
B B B (layer 3)
any help for this please?
  댓글 수: 4
Guillaume
Guillaume 2019년 9월 7일
It's still no clearer I'm afraid. Typically, a stack of colour image would be stored as a 4D array, where stack(r, c, 1, i) is the Red value of pixel (r, c) of image i, stack(r, c, 2, i) is the Green value of the same pixel of the same image, and stack(r, c, 3, i) the Blue value.
"This produces a 3D array"
If this refers to Colours(1, 1, :), then no, it produces a 1x1x12 vector.
Perhaps you have a stack of 4 images, with Colour(r, c, 1) being the R value of the 1st image at pixel (r, c) and Colour(r, c, 12) being the B value of the 4th image at pixel (r, c).
I'm not sure. Best is to tell us what the result should be for the example matrix I've given you. This would remove any ambiguity.
For that matter, it's not clear how you want to go from multiple images to a 3D array (which would contain just one image).
Guillaume
Guillaume 2019년 9월 7일
I didn't see your edit to your earlier comment.
The planes of R colours need to be merged
What does merge mean?
Stack(:,:,1) = 1, 4 RED
You can only put one value in a matrix element, so not both 1 RED and 4 RED at the same time, so how should 1, 4 (and 7 and 10) be merged?

댓글을 달려면 로그인하십시오.

답변 (1개)

Bruno Luong
Bruno Luong 2019년 9월 7일
편집: Bruno Luong 2019년 9월 7일
[m,n,p] = size(Colours);
ColoursRearrange = reshape(permute(reshape(Colours,m,n,3,[]),[1 2 4 3]),[m n p]);
  댓글 수: 3
Bruno Luong
Bruno Luong 2019년 9월 7일
편집: Bruno Luong 2019년 9월 7일
OK take an example of Colors is (2 x 2 x 6) (2 "stacks" [sic] of RGB1 = [1 2 3] and RGB2 = [11 12 13]):
Colours=repelem(reshape((1:3)'+[0 10],1,1,6),2,2,1)
That is
Colours(:,:,1) =
1 1
1 1
Colours(:,:,2) =
2 2
2 2
Colours(:,:,3) =
3 3
3 3
Colours(:,:,4) =
11 11
11 11
Colours(:,:,5) =
12 12
12 12
Colours(:,:,6) =
13 13
13 13
What do you want the reshape outcome be?
Bruno Luong
Bruno Luong 2019년 9월 7일
편집: Bruno Luong 2019년 9월 7일
[m,n,p] = size(Colours);
ColoursRearrange = reshape(permute(reshape(Colours,m,n,3,[]),[1 2 4 3]),m, [], 3)

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by