Actions
Morph-M Python - Creation and Deletion » History » Revision 3
« Previous |
Revision 3/5
(diff)
| Next »
Serge Koudoro, 10/26/2009 01:57 PM
Morph-M Python - Creation and Deletion¶
Creation...¶
Images can either be created by type and size.
im=createImage(dataCategory.dtScalar,scalarDataType.sdtUINT8)
im.setSize(256,256)
im.allocateImage()
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.
Load from file...¶
Images can be loaded from a file, and can be write to a file
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")
PNG is the best supported format.
Features...¶
Images are Python objects and as such are reference-counted and automatically destroyed when leaving the scope. This code does not leak memory:
while 1:
im=pngFileRead("hop.png")
Images are passed and copied by reference:
im2=im1
ImSetConstant(im1,255)
for pixel in im2:
print pixel
The second image is also put to 255. A new image can be created by using getSame and ImCopy:
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
The second image will have kept its values even while the first is uniformally set to 255.
Updated by Serge Koudoro about 15 years ago · 3 revisions