Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Re: Joint Histogram

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81205] Re: [mg81153] Re: Joint Histogram
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Sat, 15 Sep 2007 04:16:32 -0400 (EDT)
  • References: <fcb3gv$fg5$1@smc.vnet.net> <32961489.1189760341534.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Actually,

{ydim, xdim} = Dimensions[data];

fails, since Dimensions[data] is {120,128,3}, and we can't set a list of 
length 2 equal to a list of length 3.

But this works:

<< Histograms`
beans = Import[
   "http://www.ee.usm.maine.edu/courses/ele489/data/beans.tif";]
Histogram3D[Flatten[beans[[1, 1]] /. {r_, g_, b_} :> {r, g}, 1]]

or

Histogram3D@Flatten[beans[[1, 1, All, All, {1, 2}]], 1]

And this, I believe, is the array of counts:

h = SparseArray[
    Rule @@@
     Tally@Flatten[beans[[1, 1]] /. {r_, g_, b_} :> {r, g}, 1], {256,
     256}];

Bobby

On Fri, 14 Sep 2007 02:34:25 -0500, Mariusz Jankowski  
<mjankowski at usm.maine.edu> wrote:

> The first answer is to use function JointImageHistogram in the Digital 
> Image
> Processing package.
>
> However, the following will work:
>
>
> In[1]:= beans =
> Import["http://www.ee.usm.maine.edu/courses/ele489/data/beans.tif";]
>
> In[2]:= data = beans[[1, 1]];
>
> In[3]:= {ydim, xdim} = Dimensions[data];
>
> In[4]:= h = Table[0, {256}, {256}];
>
> In[5]:= Do[ h[[data[[i, j, 1]] + 1, data[[i, j, 2]] + 1]] += 1, {i ,  
> ydim},
> {j, xdim}]
>
>
> ... and display matrix h.
>
>
> Bye, Mariusz
>
>
>
>
>
>
>
>>>> On 9/13/2007 at 6:30 AM, in message <fcb3gv$fg5$1 at smc.vnet.net>,
> cimon<tamanna.arora at gmail.com> wrote:
>> Hello
>>
>> I am completely new to Mathematica
>> and trying to work with images in it.
>>
>> I am trying to create a joint histogram out of an image taking its red
>> and green channel.
>> I get this error
>>
>> Table::iterb: Iterator (i,1,ydim),  does not have appropriate bounds.
>> Table::iterb: Iterator (i,1,ydim),  does not have appropriate bounds.
>>
>> (see in code below)
>>
>> When I have just written the first five lines and i try to execute. i
>> dont get this error.
>> But when I have written the for loop and than i try to execute than I
>> get this error.
>>
>>
>> I am just not able to fix this out.
>> can somebody plese guide me with this.
>> -------------------------------------------------------------------------
>> penny = Import["c:\penny.ppm"];
>> Shallow[penny];
>> data = penny[[1, 1]];
>>
>> ydim = Dimensions[data][[1]];
>> xdim = Dimensions[data][[2]];
>>
>> Table::iterb: Iterator (i,1,ydim),  does not have appropriate bounds.
>> Table::iterb: Iterator (i,1,ydim),  does not have appropriate bounds.
>>
>> (* Create a Joint table
>>     Go to each (i, j)th Location in red and green Channel
>>     Get Pixel value from (i, j)th location from each red and green
>> channel
>>     Use that as an index into
>>     Joint Table and incerment the value at that index by 1
>>   *)
>>
>> Joint = Table[0, {ti, 1, 256}, {tb, 1, 256}];
>> Dimensions[Joint];
>>
>>
>> For[fi = 0, fi =E2=89=A4 xdim, fi++
>>       For[fj = 0, fj =E2=89=A4 ydim, fj++
>>             Joint[redChannel[[fi, fj]], greenChannel[[fi, fj]]] + >> 1]];
>>
>> Show[Graphics[Raster[Joint], AspectRatio -> 1, Axes -> True]]
>>
>>
>>
> --------------------------------------------------------------------------- >
>> ------------------------------------
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Stylesheet Question
  • Next by Date: Re: Input Format
  • Previous by thread: Re: Joint Histogram
  • Next by thread: rationalize numerator of quotient