20.4 Using Python to Process Images

You can access and process images from the Image Window using the originpro package included with the Embedded Python feature in Origin.

The following is a simple code sample where an image stack from an external files is imported into an Image Window, and one of the images is then inverted by using the Scikit-Image Python package:

import originpro as op
import numpy as np
from skimage.util import invert
#load image stack
fn = op.path('e') + r'Samples\Image Processing and Analysis\*.tif'
iw=op.new_image()
iw.from_file(fn)
print(iw.frames)
#get the 3 image
im2 = iw.to_np2d(2)
im2 *= 2
im2 = invert(im2)
#put it back into 2nd image
iw.from_np2d(im2, 1)
iw.set_int('NAV',1)

For more code samples, please refer to the Images section in this page: Python Code Samples