[Tutor] Image GetData and SetData stuff

David McDonnell David McDonnell" <dave@blinkworks.com.au
Wed Apr 23 15:13:01 2003


This is a multi-part message in MIME format.

------=_NextPart_000_009E_01C308E9.F863FB50
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi All,

I'm new to the list, been lurking for a week or so now and am completely =
new to python script, although i'm faimilar with some other scripting =
languages such as MaxScript (for 3DSMax).

Anyway i'm trying to do some image manipulation code, which will =
basically require me to grab the data from an image, mainipulate the =
pixel colours etc in code and then output the resulting image. Basically =
one fo the things i want to be able to do is to compare the R,G,B values =
of pixels in the image, alter them if certain conditions are met and =
then output the results. I've got the image displaying, getting the data =
and just setting the data to same thing at this point. Now how do i work =
on the actual data? I've tried printing out the Data to try and see how =
its presented etc (bad mistake... total gibberish to me and makes my =
system speaker beep constantly for about 5 minutes).=20
Any ideas or pointers anyone? The code is below. Also i did have what i =
wanted working previously using the wxWindows GetRed, GetBlue, and =
GetGreen, comparing them and outputting using SetRGB though the whole =
thing seemed too slow (about 10 - 15 seconds for 1 image, although most =
of that time seemed to be taken up in the Get Stage)

Much appreciated

dave



class MainWindow(wxFrame):
 def __init__(self,parent,id,title):

  wxFrame.__init__(self,parent,-4,title,size=3D(800,600),
     style=3DwxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
  self.CreateStatusBar()
 =20
  self.panel =3D wx.wxPanel(self, -1)
  file =3D 'p_34.bmp'
  bmp =3D wxImage(opj(file), wxBITMAP_TYPE_BMP).ConvertToBitmap()
  wxStaticBitmap(self.panel, -1,bmp, (15, 30))#, (bmp.GetWidth(), =
bmp.GetHeight()))
  =20
  bmp2 =3D wxImage(opj(file), wxBITMAP_TYPE_BMP)
  print "Getting Data"
  data =3D bmp2.GetData()
  print "Got Data"
 =20
 =20
  bmp2.SetData(data)
  bmp =3D wxBitmapFromImage(bmp2) =20
  wxStaticBitmap(self.panel, -1,bmp, (500, 30))#, (bmp.GetWidth(), =
bmp.GetHeight()))

=20
  self.Show(true)

------=_NextPart_000_009E_01C308E9.F863FB50
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi All,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I'm new to the list, been lurking for a week or so =
now and am=20
completely new to python script, although i'm faimilar with some other =
scripting=20
languages such as MaxScript (for 3DSMax).</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Anyway i'm trying to do some image manipulation =
code, which=20
will basically require me to grab the data from an image, mainipulate =
the pixel=20
colours etc in code and then output the resulting image. Basically one =
fo the=20
things i want to be able to do is to compare the R,G,B values of pixels =
in the=20
image, alter them if certain conditions are met and then output the =
results.=20
I've got the image displaying, getting the data and just setting the =
data to=20
same thing at this point. Now how do i work on the actual data? I've =
tried=20
printing out the Data to try and see how its presented etc (bad =
mistake... total=20
gibberish to me and makes my system speaker beep constantly for about 5=20
minutes). </FONT></DIV>
<DIV><FONT size=3D2>Any ideas or pointers anyone? The code is below. =
Also i did=20
have what i wanted working previously using the wxWindows GetRed, =
GetBlue, and=20
GetGreen, comparing them and outputting using SetRGB though the whole =
thing=20
seemed too slow (about 10 - 15 seconds for 1 image, although most of =
that time=20
seemed to be taken up in the Get Stage)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Much appreciated</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>dave</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>class MainWindow(wxFrame):<BR>&nbsp;def=20
__init__(self,parent,id,title):</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT=20
size=3D2>&nbsp;&nbsp;wxFrame.__init__(self,parent,-4,title,size=3D(800,60=
0),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style=3DwxDEFAULT_FRAME_STYLE|wxNO_F=
ULL_REPAINT_ON_RESIZE)<BR>&nbsp;&nbsp;self.CreateStatusBar()<BR>&nbsp;&nb=
sp;<BR>&nbsp;&nbsp;self.panel=20
=3D wx.wxPanel(self, -1)<BR>&nbsp;&nbsp;file =3D =
'p_34.bmp'<BR>&nbsp;&nbsp;bmp =3D=20
wxImage(opj(file),=20
wxBITMAP_TYPE_BMP).ConvertToBitmap()<BR>&nbsp;&nbsp;wxStaticBitmap(self.p=
anel,=20
-1,bmp, (15, 30))#, (bmp.GetWidth(),=20
bmp.GetHeight()))<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;bmp2 =3D =
wxImage(opj(file),=20
wxBITMAP_TYPE_BMP)<BR>&nbsp;&nbsp;print "Getting =
Data"<BR>&nbsp;&nbsp;data =3D=20
bmp2.GetData()<BR>&nbsp;&nbsp;print "Got=20
Data"<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;bmp2.SetData(data)<B=
R>&nbsp;&nbsp;bmp=20
=3D =
wxBitmapFromImage(bmp2)&nbsp;&nbsp;<BR>&nbsp;&nbsp;wxStaticBitmap(self.pa=
nel,=20
-1,bmp, (500, 30))#, (bmp.GetWidth(), bmp.GetHeight()))</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;<BR>&nbsp;&nbsp;self.Show(true)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_009E_01C308E9.F863FB50--