How to reshape 2D matrix to build RGB Image in Matlab

1 view (last 30 days)
I have data from a text file that represents RGB values in each column, for instance, the Germany flag can be represented by this:
R G B
0 0 0 <-- black
1 0 0 <-- red
1 0.87 0 <--- yellow
0 0 0 <-- flag repeated...
1 0 0
1 0.87 0
0 0 0 <-- again---
1 0 0
1 0.87 0
Now, what I want is to build an image from that information, and it works perfect when there is only 1 pixel wide, I can do the following to create the flag:
%load the data to myData
Germany = reshape(myData,9,1,3);
image(Germany)
However, when I want a more complex picture, lets say a 1px-wide Germany flag (as in previous example), followed by a 3px-wide Italian flag, I would have something like this:
German Flag| Green | White | Red |
0.0 0.0 0.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0
1.0 0.9 0.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0
... This repeats another 2 times ((1+2)x3=9)
What I tried was:
GermanyItaly = reshape(myData,9,4,3);
But did not work, any help is appreciated

Answers (1)

Image Analyst
Image Analyst on 5 Mar 2014
I think you should be using repmat() rather than reshape(). repmat() will copy a row or column or whole block a number of times. In essence, "stitch" together similar blocks of pixels into a bigger block.

Community Treasure Hunt

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

Start Hunting!