Project

General

Profile

Morph-M Python - Creation and Deletion » History » Version 5

Serge Koudoro, 10/26/2009 02:00 PM

1 2 Serge Koudoro
h1. *Morph-M Python - Creation and Deletion*
2 1 Serge Koudoro
3
h3{color:#8B0000}. +Creation...+
4
5
Images can either be created by type and size.
6
7
<pre><code class="ruby">
8
im=createImage(dataCategory.dtScalar,scalarDataType.sdtUINT8)
9
im.setSize(256,256)
10
im.allocateImage()
11
</code></pre>
12
13
which type and size are this following value:
14
15
    * *Type*: _sdtINT8, sdtINT16, sdtINT32, sdtINT64, sdtUINT8, sdtUINT16, sdtUINT32, sdtUINT64, sdtFloat, sdtDouble, sdtBIT, sdtOffset, sdtLabel, sdtSTR, sdtObject, sdtCompound, sdtList, sdtMap, sdtPair_.
16
    * *size*: _dtScalar, dtAngular, dtComplex, dtPixel3, dtPixel4, dtOffsetList, dtPointer, dtArray, dtImage, dtNeighborhood, dtVariant, dtCVariant_. 
17
18
h3{color:#8B0000}. +Load from file...+
19
20
Images can be loaded from a file, and can be write to a file
21
22
<pre><code class="ruby">
23
im2=pngFileRead("foo.png")
24
im2=bmpFileRead("foo.bmp")
25
im2=csvFileRead("foo.csv")
26
im2=jpegFileRead("foo.jpg")
27
pngFileWrite(im2,"foo.png")
28
bmpFileWrite(im2,"foo.bmp")
29
csvFileWrite(im2,"foo.csv")
30
jpegFileWrite(im2,"foo.jpg")
31
#generic function
32
im2=fileRead("foo.png")
33
fileWrite(im2, "foo.jpg")
34
</code></pre>
35
36
PNG is the best supported format.
37
38 4 Serge Koudoro
h3{color:#8B0000}. +Load from List...+
39
40 5 Serge Koudoro
<pre><code class="ruby">
41 4 Serge Koudoro
im = createImage(dataCategory.dtScalar,scalarDataType.sdtUINT32 )
42
im.setSize(3,3)
43
im.allocateImage()
44
45
L=[ 1,2,3,4,5,6,7,8,9]
46
im.fromList(L)
47 5 Serge Koudoro
</code></pre>
48 4 Serge Koudoro
49 1 Serge Koudoro
h3{color:#8B0000}. +Features...+
50
51
Images are Python objects and as such are reference-counted and automatically destroyed when leaving the scope. This code does not leak memory:
52
53
<pre><code class="ruby">
54
while 1:
55 3 Serge Koudoro
   im=pngFileRead("hop.png")
56 1 Serge Koudoro
57
</code></pre>
58
59
Images are passed and copied by reference:
60
61
<pre><code class="ruby">
62
im2=im1
63
ImSetConstant(im1,255)
64
for pixel in im2:
65 3 Serge Koudoro
   print pixel
66 1 Serge Koudoro
</code></pre>
67
68
The second image is also put to 255. A new image can be created by using getSame and ImCopy:
69
70
<pre><code class="ruby">
71
im2=im1.getSame()                   #or im2=ImCreateSame(im1)
72
im3=im1.ImCreateSame(im1, "UINT16") #changing image type
73
ImCopy(im1,im2)
74
ImSetConstant(im1,255)
75
for pixel in im2:
76 3 Serge Koudoro
   print pixel
77 1 Serge Koudoro
</code></pre>
78
79
The second image will have kept its values even while the first is uniformally set to 255.