crop_channel#

Crop channels from bifurcation AN images. In a typical bifurcation experiment, we have a 3-way micro-channel photoprinted on a resin. This micro-channel is cast on the active microtubule system at an oil-water interface. The chaotic turbulent-like motions of microtubules will be rectified by the micro-channels. Ratchet structures are used to set one of the channels as inlet. The flow then goes into either remaining channels, or into both at certain fractions. We study what is the “preferred” bifurcation of the flow. In the cropped images, predetermined positive (+) direction always points upward.

This code crops the original multi-microchannel images into single channels, to allow more efficient PIV analysis. On top of cropping, the code also remove the background static feature from the images, by dividing the images by the median of the image stack. The images are then converted from float64 to 8-bit to save the storage space.

Syntax

python crop_channel.py crop_data nd2Dir method
  • crop_data: the directory to a *.csv file specifying how the raw images should be cropped. Typically, it consists 6 rows, where rows 1, 3, 5 contain rotation information, rows 2, 4, 6 contain cropping information. The image will rotate according to row 1, and cropped according to row 2, and so on so forth. The file is typically generated using ImageJ measurement tool.

  • nd2Dir: full directory of the *.nd2 file to be cropped.

  • method: rotate or map.

Warning

rotate and map methods use different crop_data.

The folder structure is illustrated below:

|-- nd2_folder
    |-- 00.nd2
    |-- 01.nd2
    |-- ...
    |-- crop_channel
        |-- 00_A.tif
        |-- 00_B.tif
        |-- 00_C.tif

Note

  • When creating crop_data in ImageJ, only select “bounding rectangle” in “Analyze -> Set measurements…”

  • When creating crop_data, DO remember to remove the scale !!!

Edit

  • Nov 03, 2022 – Initial commit.

  • Nov 23, 2022 – To make the workflow consistent with Claire’s, it is more convenient to crop the channel region directly from the *.nd2 file, and save as tifstack. Now crop directly from *.nd2 files to tifstack.

  • Jan 05, 2023 – Adapt myimagelib import style.

  • Jan 24, 2023 – (i) Check the existence of output files, e.g. 00_A.tif, 00_B.tif, 00_C.tif, (ii) print nd2 file name as progress bar label.

  • Feb 08, 2023 – Rewrite in function wrapper form, to make autodoc work properly. (autodoc import the script and execute it, so anything outside if __name__=="__main__" will be executed, causing problems)

  • Mar 30, 2023 – (i) Add “map” method, in addtion to “rotate”, (ii) generate a crop region indicator on the raw image.

  • Mar 31, 2023 – Explicitly convert image dtype to float32 when dividing median to reduce memory usage.