creating channels in an array

2 visualizaciones (últimos 30 días)
Pravitha A
Pravitha A el 12 de Feb. de 2020
Comentada: Pravitha A el 12 de Feb. de 2020
I saw a code from rgbe bayer conversion program as follows:
% subsample HDR image to get RGGB Bayer pattern
I(1:2:end, 1:2:end) = HDR(1:2:end, 1:2:end, 1); % R
I(1:2:end, 2:2:end) = HDR(1:2:end, 2:2:end, 2); % G odd
I(2:2:end, 1:2:end) = HDR(2:2:end, 1:2:end, 2); % G even
I(2:2:end, 2:2:end) = HDR(2:2:end, 2:2:end, 3); % B
To understand this concept i tried this code with simple arrays in command window as follows:
>> x=[1 2 3 4 5;6 7 8 9 10;11 12 13 14 15;16 17 18 19 20]
x =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
>> h=[20 19 18 17 16; 15 14 13 12 11; 10 9 8 7 6; 5 4 3 2 1]
h =
20 19 18 17 16
15 14 13 12 11
10 9 8 7 6
5 4 3 2 1
>> x(1:2:end,1:2:end)=h(1:2:end,1:2:end,1)
x =
20 2 18 4 16
6 7 8 9 10
10 12 8 14 6
16 17 18 19 20
>> x(1:2:end,2:2:end)=h(1:2:end,2:2:end,2)
error: h(_,_,2): but h has size 4x5
What does this error mean?
Why did it happen?

Respuesta aceptada

Stephen23
Stephen23 el 12 de Feb. de 2020
Editada: Stephen23 el 12 de Feb. de 2020
"What does this error mean?"
You are trying to access array elements that do not exist!
You defined h to have size 4x5(x1x1x1...):
h = [4x5x1] % you defined |h| to have this size
h(...,..,2) % what the indexing refers to: note that 2>1
The RHS indexing refers to a 3D array, but your example h array only has size 1 along the third dimension. So when the indexing refers to the 2nd "page", it throws an error because your array only has one "page":
This third dimension is used for storing image RGB data:
If you want your example to work you will need to create an h array that has atleast size 3 along the third dimension (i.e. atleast 3 pages), e.g.:
>> h = permute(reshape(60:-1:1,5,4,3),[2,1,3])
h(:,:,1) =
60 59 58 57 56
55 54 53 52 51
50 49 48 47 46
45 44 43 42 41
h(:,:,2) =
40 39 38 37 36
35 34 33 32 31
30 29 28 27 26
25 24 23 22 21
h(:,:,3) =
20 19 18 17 16
15 14 13 12 11
10 9 8 7 6
5 4 3 2 1

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by