extract#

This program extracts light-weight information from data generated by bacteria.vi at Clement lab, PMMH, ESPCI.

Videos will be recognized in pairs: anchor and record. Original video folders are named as “yyyy-mm-dd_hhhmmmsss”. Anchor video folders will be renamed by adding “_ref_n” at the end of the original name, and the corresponding record video will be renamed by adding “_n” at the end of the original name. So after a day of experiment, we will have a main folder containing subfolders, with the following structure:

|-- main folder
    |-- 2021-07-21_16h02m43s_ref_1
    |-- 2021-07-21_16h02m43s_1
    |-- 2021-07-21_16h03m43s_ref_2
    |-- 2021-07-21_16h03m43s_2
    |-- 2021-07-21_16h04m43s_ref_3
    |-- 2021-07-21_16h04m43s_3
    |-- ...

This code will extract the 1st image “ref.tif” from an anchor video, for example in “2021-07-21_16h02m43s_ref_1”. Text files “Track.txt”, “StagePosition.txt” and “RawImageInfo.txt” in the corresponding record video folder will be extracted, too. These 4 files will be saved under folder “main folder/extract/n”.

The resulting folder structure will be the following:

|-- main folder
    |-- 2021-07-21_16h02m43s_ref_1
    |-- 2021-07-21_16h02m43s_1
    |-- 2021-07-21_16h03m43s_ref_2
    |-- 2021-07-21_16h03m43s_2
    |-- 2021-07-21_16h04m43s_ref_3
    |-- 2021-07-21_16h04m43s_3
    |-- ...
    |-- extract
        |-- 1
            |-- ref.tif
            |-- Track.txt
            |-- StagePosition.txt
            |-- RawImageInfo.txt
        |-- 2
        |-- 3
        |-- ...

Usage

  1. In command line, enter the directory of extract.py

  2. Run python extract.py main_folder, here the main_folder is the folder containing video subfolders.

Syntax

python extract.py main_folder

Edit

  • Oct 06, 2021 – Initial commit.

  • Oct 07, 2021 – Add date stamp to the extracted folders. Number format changes to %04d. “{:04d}_yyyy-mm-dd”. Change the condition to ignore folder. Now ignore everything that has less than 2 “_“‘s.

  • Sep 20, 2022 – Only read the first image from binary .raw file, instead of loading whole stack and slice the first image. This should speed up the program. Check if extract exists, if so, continue.

  • 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)