wx.ImageHistogram lose functionality?

Hello!

Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?

[I believe it happened due the limited SWIG ability to understand tricky C++
code used in wxWidgets. wxImageHistogramm actually inherited from the
HashMap class but this inheritance is "hidden" because weird macros (like
WX_DECLARE_EXPORTED_HASH_MAP) are used for building wxImageHistogramBase
class.]

    Vladimir Ignatov

Vladimir Ignatov wrote:

Hello!

Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?

[I believe it happened due the limited SWIG ability to understand tricky C++
code used in wxWidgets. wxImageHistogramm actually inherited from the
HashMap class but this inheritance is "hidden" because weird macros (like
WX_DECLARE_EXPORTED_HASH_MAP) are used for building wxImageHistogramBase
class.]

Correct.

What methods do you think should be exposed?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hello Robin!

Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?

Correct.
What methods do you think should be exposed?

In a case of ImageHistogram I need a method what return count of pixels with
the given key (rgb tripple).

···

-------
image = wx.Image( ... )
hist = wx.ImageHistogram()
image.ComputeHistogram( hist )
key = hist.MakeKey( r,g,b )
-------- so far is all ok ----

now I need something like:

num_pixels = hist[ key ]
     or
num_pixels = hist.Count( key )
    or
num_pixels = hist.GetCount( key )
    or even
num_pixels = hist.Get( key )
--------------------------

On the C++ side this functionality provided by HashMap's operator - there
is no named method for doing it.

---------------
from include\wx\hashmap.h:

#define _WX_DECLARE_HASH_MAP ...
....
mapped_type& operator( const const_key_type& key ) \
    { \
        return GetOrCreateNode( CLASSNAME##_wxImplementation_Pair( key,
mapped_type() ) )->m_value.second; \
    } \
--------------

I am not familiar with SWIG and don't have an idea how easy or difficult to
expose operator to python. If this is tough, then I would like to see
method (named maybe Count or GetCount or Get) that exposes cpp's
functionality to Python.

    Vladimir Ignatov

Vladimir Ignatov wrote:

Hello Robin!

Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?

Correct.
What methods do you think should be exposed?

In a case of ImageHistogram I need a method what return count of pixels with
the given key (rgb tripple).

-------
image = wx.Image( ... )
hist = wx.ImageHistogram()
image.ComputeHistogram( hist )
key = hist.MakeKey( r,g,b )
-------- so far is all ok ----

now I need something like:

num_pixels = hist[ key ]
    or
num_pixels = hist.Count( key )
   or
num_pixels = hist.GetCount( key )
   or even
num_pixels = hist.Get( key )
--------------------------

Okay, I've added GetCount and GetCountRGB methods that work like this:

>>> import wx
>>> b = wx.EmptyBitmap(10,10)
>>> dc = wx.BufferedDC(None, b)
>>> dc.SetBackground(wx.Brush("white"))
>>> dc.Clear()
>>> dc.SetPen(wx.Pen("black"))
>>> dc.DrawPoint(5,5)
>>> dc.SetPen(wx.Pen("blue"))
>>> dc.DrawLine(5,0, 10,10)
>>> del dc
>>> i = wx.ImageFromBitmap(b)
>>> h = wx.ImageHistogram()
>>> i.ComputeHistogram(h)
3
>>> h.GetCount(h.MakeKey(0,0,0))
1
>>> h.GetCount(h.MakeKey(255,255,255))
90
>>> h.GetCountRGB(1,1,1)
0
>>> h.GetCountRGB(255,255,255)
90
>>> h.GetCountRGB(0,0,255)
9

Does that meet your needs?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi, Robin!

Okay, I've added GetCount and GetCountRGB methods that work like this:

>>> import wx
>>> b = wx.EmptyBitmap(10,10)
>>> dc = wx.BufferedDC(None, b)
>>> dc.SetBackground(wx.Brush("white"))
>>> dc.Clear()
>>> dc.SetPen(wx.Pen("black"))
>>> dc.DrawPoint(5,5)
>>> dc.SetPen(wx.Pen("blue"))
>>> dc.DrawLine(5,0, 10,10)
>>> del dc
>>> i = wx.ImageFromBitmap(b)
>>> h = wx.ImageHistogram()
>>> i.ComputeHistogram(h)
3
>>> h.GetCount(h.MakeKey(0,0,0))
1
>>> h.GetCount(h.MakeKey(255,255,255))
90
>>> h.GetCountRGB(1,1,1)
0
>>> h.GetCountRGB(255,255,255)
90
>>> h.GetCountRGB(0,0,255)
9

Does that meet your needs?

Great! Thanks Robin. This is exactly that I am looking for.

    Vladimir Ignatov