MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bitmap data extraction (matrix of matrix)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76481] Re: Bitmap data extraction (matrix of matrix)
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 23 May 2007 05:11:44 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f2u51n$k09$1@smc.vnet.net>

mkorneck at nd.edu wrote:
> Hello,
> 
> This is most likely a simple question for those who use Mathematica on
> a semi-regular basis, but ...
> 
> I have a 512x512 matrix composed of 1x3 matrix elements, and want to
> create a 512x512 matrix composed of a single value in the original 1x3
> elements.
> 
> That doesn't look very well defined, so please let me explain further
> in the hopes of clarifying what I am after.
> 
> It's a bitmap image file (512x512) and I want to extract a part of the
> "raw" data for further processing. The raw data in the original file
> consists of values for the red, green and blue (RGB). I would like to
> create a matrix composed of only the *red* values across the 512x512
> array.
> 
> As a simplified example ....
> 
> Given RGB = {{1,0,1},{2,3,2},{4,6,4},{3,2,1}}
>                     {{9,1,3},{3,2,1},{4,3,3},{5,3,2}}
> 
> 
> I would like to end up with R = {1,2,4,3}
>                                             {9,3,4,5}
> 
> Thank you for your time,
> 
> Mike K.

Hi Mike,

You can use Part (or Take), as in the following code:

`In[1]:=
img = {{{1, 0, 1}, {2, 3, 2}, {4, 6, 4}, {3, 2, 1}},
     {{9, 1, 3}, {3, 2, 1}, {4, 3, 3}, {5, 3, 2}}};

redpts = img[[All,All,1]]
greenpts = img[[All,All,2]]
bluepts = img[[All,All,3]]

Out[2]=
{{1, 2, 4, 3}, {9, 3, 4, 5}}

Out[3]=
{{0, 3, 6, 2}, {1, 2, 3, 3}}

Out[4]=
{{1, 2, 4, 1}, {3, 1, 3, 2}}

Cheers,
Jean-Marc



  • Prev by Date: Re: Evaluation Question
  • Next by Date: Re: Re: Mathematica 6 review [first impressions]
  • Previous by thread: Re: Bitmap data extraction (matrix of matrix)
  • Next by thread: Re: Bitmap data extraction (matrix of matrix)