Morph-M Python - Creation and Deletion » History » Version 2
Serge Koudoro, 10/23/2009 03:52 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 | h3{color:#8B0000}. +Features...+ |
||
39 | |||
40 | Images are Python objects and as such are reference-counted and automatically destroyed when leaving the scope. This code does not leak memory: |
||
41 | |||
42 | <pre><code class="ruby"> |
||
43 | while 1: |
||
44 | im=pngFileRead("hop.png") |
||
45 | |||
46 | </code></pre> |
||
47 | |||
48 | Images are passed and copied by reference: |
||
49 | |||
50 | <pre><code class="ruby"> |
||
51 | im2=im1 |
||
52 | ImSetConstant(im1,255) |
||
53 | for pixel in im2: |
||
54 | print pixel |
||
55 | </code></pre> |
||
56 | |||
57 | The second image is also put to 255. A new image can be created by using getSame and ImCopy: |
||
58 | |||
59 | <pre><code class="ruby"> |
||
60 | im2=im1.getSame() #or im2=ImCreateSame(im1) |
||
61 | im3=im1.ImCreateSame(im1, "UINT16") #changing image type |
||
62 | ImCopy(im1,im2) |
||
63 | ImSetConstant(im1,255) |
||
64 | for pixel in im2: |
||
65 | print pixel |
||
66 | </code></pre> |
||
67 | |||
68 | The second image will have kept its values even while the first is uniformally set to 255. |