Project

General

Profile

Morph-M Python - Creation and Deletion » History » Revision 2

Revision 1 (Serge Koudoro, 10/23/2009 03:52 PM) → Revision 2/5 (Serge Koudoro, 10/23/2009 03:52 PM)

h1. *Morph-M Morph-M Python - Creation and Deletion* Deletion 

 h3{color:#8B0000}. +Creation...+ 

 Images can either be created by type and size. 

 <pre><code class="ruby"> 
 im=createImage(dataCategory.dtScalar,scalarDataType.sdtUINT8) 
 im.setSize(256,256) 
 im.allocateImage() 
 </code></pre> 

 which type and size are this following value: 

     * *Type*: _sdtINT8, sdtINT16, sdtINT32, sdtINT64, sdtUINT8, sdtUINT16, sdtUINT32, sdtUINT64, sdtFloat, sdtDouble, sdtBIT, sdtOffset, sdtLabel, sdtSTR, sdtObject, sdtCompound, sdtList, sdtMap, sdtPair_. 
     * *size*: _dtScalar, dtAngular, dtComplex, dtPixel3, dtPixel4, dtOffsetList, dtPointer, dtArray, dtImage, dtNeighborhood, dtVariant, dtCVariant_.  

 h3{color:#8B0000}. +Load from file...+ 

 Images can be loaded from a file, and can be write to a file 

 <pre><code class="ruby"> 
 im2=pngFileRead("foo.png") 
 im2=bmpFileRead("foo.bmp") 
 im2=csvFileRead("foo.csv") 
 im2=jpegFileRead("foo.jpg") 
 pngFileWrite(im2,"foo.png") 
 bmpFileWrite(im2,"foo.bmp") 
 csvFileWrite(im2,"foo.csv") 
 jpegFileWrite(im2,"foo.jpg") 
 #generic function 
 im2=fileRead("foo.png") 
 fileWrite(im2, "foo.jpg") 
 </code></pre> 

 PNG is the best supported format. 

 h3{color:#8B0000}. +Features...+ 

 Images are Python objects and as such are reference-counted and automatically destroyed when leaving the scope. This code does not leak memory: 

 <pre><code class="ruby"> 
 while 1: 
 im=pngFileRead("hop.png") 

 </code></pre> 

 Images are passed and copied by reference: 

 <pre><code class="ruby"> 
 im2=im1 
 ImSetConstant(im1,255) 
 for pixel in im2: 
 print pixel 
 </code></pre> 

 The second image is also put to 255. A new image can be created by using getSame and ImCopy: 

 <pre><code class="ruby"> 
 im2=im1.getSame()                     #or im2=ImCreateSame(im1) 
 im3=im1.ImCreateSame(im1, "UINT16") #changing image type 
 ImCopy(im1,im2) 
 ImSetConstant(im1,255) 
 for pixel in im2: 
 print pixel 
 </code></pre> 

 The second image will have kept its values even while the first is uniformally set to 255.