Command to save images in TIFF format rather than TIC format

Issue #228 new
William Nguyen created an issue

I’m using the built in camera plugin for Ximea on ITOM. In the tutorial, the command saveTIC saves the acquired images in the TIC format. I’m wondering if there is a command to save the images in TIFF format instead?

Thank you!

Comments (12)

  1. M. Gronle

    Where did you find the saveTIC command, since I would say, that this is a spelling mistake or an error in any tutorial or documentation. Please give me a hint where you found it, such that we can potentially correct this.

    The right algorithm, implemented in the dataObjectIO plugin and generally denoted as filter is called saveTiff.

    Please open the Plugin Help Viewer in the Help menu of itom and search for saveTiff. Then you get a description of this algorithm.

    The traditional, generic way to call this algorithm is

    import itom
    
    img = itom.dataObject([100, 100], "uint16")
    
    itom.filter("saveTiff", img, "C:/temp/myimg.tiff", "gray16")
    

    From the current master or the upcoming itom 4.2 on, these algorithms are also directly accessible and its parameters are displayed in the calltips and auto completion, if they are called by this new, recommended way:

    import itom
    
    img = itom.dataObject([100, 100], "uint16")
    
    itom.algorithms.saveTiff(img, "C:/temp/myimg.tiff", "gray16")
    # or
    itom.algorithms.saveTiff(img, filename="C:/temp/myimg.tiff", palette="gray16")
    

    Other image formats, like jpg, png, pgm, ppm, bmp… also also supported by other algorithms in the dataObjectIO plugin. See the Plugin Help Viewer, too.

    Furthermore, methods like itom.filterHelp can also be used to obtain a list of algorithms or a description of an algorithm in the command line of itom.

  2. William Nguyen reporter

    Hello, so I got image saving code working but I can only save 1 data object by using the suggested itom.filter method (see below). At the moment, it can only save ‘d' but I want to save “result” into the tiff file. The purpose of this code is to see many images together to see what happens to the fringes of an interferometer experiment (similar to what happens in the ximea cam app when you click record loop).

                #image saving code
                for j in range(0,10):
                    camera.acquire()
                    camera.getVal(d)
                    result.append(d.copy())
                 #save list of image
                angle_value = (i+1)*(-directedAngleInc)
                filter("saveTiff", d, "E:/William Nguyen/angle"+str(angle_value)+"tiff", "gray16")
    

  3. M. Gronle

    Hi William,

    the saveTiff algorithm of itom is not able to save a stack of images in one tiff file. Maybe, there are other python packages, that can do this (http://soft-matter.github.io/pims/v0.5/tiff_stack.html). You can usually pass a dataObject to any argument that accepts an numpy.ndarray-like object. Even, if only a real np.ndarray is accepted, you can easily convert
    any dataObject to a numpy array by

    npArray = np.array(myDataObject, copy=False)
    

    Usually, the numpy constructor makes a deep copy of data, pass copy=False to make a shallow copy (only possible if data types are compatible.

    Another possibility would be to stack all your images into a 3d-dataObject, e.g. by

    myDObjStack = dataObject.dstack(result) # if result is a sequence of dataObjects of same shape and type
    

    Then, you can save this stack as an idc file, and reload it using loadIDC if required. The itom 2d plot also accepts such an image stack.
    If this is the case, you will find a spin box in the toolbar of the plot that allows scrolling through the different image planes. Additionally, there
    are tools in the toolbar of the plot to show a cross cut as 1D plot along the z-direction at the x,y coordinate of the mouse click or it is also
    possible to show a 2d projection along a line, indicated by the mouse, an the z-direction. These features can maybe help to visually analzye your
    interferograms in detail.

    Just one example:

    myStack = dataObject.rand([100, 1000, 1000], 'float32')
    myStack.axisScales=(1, 0.02, 0.02)
    myStack.axisUnits=("", "nm", "nm")
    myStack.setTag("title", "Demo object")
    plot2(myStack, "itom2dqwtplot") # the plot class name can be omitted if the default plot class for 2d plots is properly set.
    

    Highlighted are the special buttons in the toolbar and you can also see, that units, scalings, titles etc. are automatically considered in the plot.

    If I select the z-stack button and click somewhere on the canvas, a 1d linecut over all 100 z-layers is displayed:

    Cheers

    Marc

  4. William Nguyen reporter

    I’m looking at the pims package to stack my images as a TIFF file (http://soft-matter.github.io/pims/v0.5/tiff_stack.html). I installed this in itom. My approach right now is to save the individual image as a single tiff using:

    itom.algorithms.saveTiff(img, filename="C:/temp/myimg.tiff", palette="gray16")

    Then I will stack them using the pims package. However, the algorithms.saveTiff returned an error of:

    Runtimeerror: cv: inwrite exited with false!

  5. William Nguyen reporter

    I think this might be a new problem with itom 4.2? I don’t recall having this error with this particular line when I used itom 4.1 a week ago

  6. M. Gronle

    Hi William,

    are you sure that the directory exists? I tried to save an image with the itom 4.2 setup and only got your exception if the directory (here: C:/temp) does not exist. The error message has to be improved → task for me.

  7. Log in to comment