Code Monkey home page Code Monkey logo

specklepy's Introduction

SpecklePy

Introduction

Repository contains simple Python scripts, designed to demonstrate techniques of laser speckle imaging. Scrips are based on OpenCV library. The general principle of the programs is to connect to capturing device and start imaging the speckle activity in the live mode.

Alt text

Check out the youtube videos to see the code in action:

For more on the speckle imaging technique, see the publications below:

General description

Required Python packages (as detailed in "requirements.txt"):

  • opencv-python
  • numpy

Before running the script set the correct value of the "device_id" variable. Setting this value to "0" means "connect with the first capturing device". If you are using laptop with build-in webcam, then "0" refers to this camera. Any other device, such as USB external camera will have higher id numbers (1, 2 etc.).

Pressing "q" on keyboard terminates both scripts. Switching "OFF/ON" slider to position "1" turns on the live processing mode.

Camera settings are controlled by "EXPOSURE" and "GAIN" sliders.

Scripts allow to capture data as still images or videos. Recording starts by pressing the "s" button on keyboard. Recording modes are selected with the "MODE" and "TIME" sliders. Following options are available:

MODE TIME Resulting recording mode
0 0 Recording sigle still image in TIFF format
0 >0 Recording series of still images in TIFF format, in intervals set by TIME slider. Capturing stars by pressing "s" button. Pressing the "s" button again stops recording.
1 0 Recording single video into AVI file format. Capturing stars by pressing "s" button. Pressing the "s" button again stops recording.
1 >0 Recording single video into AVI file format. Capturing stars by pressing "s" button. Recording stops automatically after number of seconds set on TIME slider.
2 >=0 Recording single time-lapse video into AVI file format. Capturing stars by pressing "s" button. Pressing the "s" button again stops recording. Video frames are captured in intervals set by TIME slider (in seconds).

lasca_s.py

Script calculates speckle activity based on spatially resolved laser speckle contrast analysisi algorith (LASCA). Conrast is calculated as ratio of the standard deviation to the mean value of pixels intensities within local processing window. Size of processing window is controlled by "kernel_size" variable.

The lasca_s.py script runs in two separate windows - control window and preview window. Preview window shows processed or unprocessed video stream. Control window contains trackbars used to control the data processing.

Description of script specific trackbars:

  • MIN_GRAY - pixel gray level threshold; pixels with gray level lower than MIN_GRAY will not be analyzed
  • SCALE - used to scale values of the output speckle activity map

esf_s.py

In brief, conventional Fujii coefficient is calculated from a arbitrary chosen number of captured video frames. Therefore, it requires to store a buffer of previously calculated values, which is updated by new data.

The ESF algorithm does not require to store captured frames in separate buffer. The previously calculated values are taken into account by means of exponentially moving average algorithm. The data accumulation rate can be freely adjusted. High accumulation rate means that only recent data is taken into account.

Please check the following publication for more detailed description of both methods: Pieczywek et al. (2017), "Exponentially smoothed Fujii index for online imaging of biospeckle spatial activity" Computers and Electronics in Agriculture 142, pp. 70-78 https://doi.org/10.1016/j.compag.2017.08.018

The esf_s.py script runs in two separate windows - control window and preview window. Preview window shows processed or unprocessed video stream. Control window contains trackbars used to control the data processing.

Description of script specific trackbars:

  • MIN_GRAY - pixel gray level threshold; pixels with gray level lower than MIN_GRAY will not be analyzed
  • MIN_DIFF - minimum gray level difference between two consecutive frames; pixels which show changes in gray level lower than MIN_DIFF will not be analyzed
  • SCALE - used to scale values of the output speckle activity map
  • ACC_RATE - adjusts the data accumulation rate

video_to_lasca.py & image_to_lasca.py

Both scripts take raw data stored as files and convert them to LASCA images. Video sequences saved in avi files or single images saved in tiff files can be processed. Variables "gray_threshold" and "max_value" are used to adjust gray level threshold and scale values of the output speckle activity maps, respectively. Size of processing window is controlled by "kernel_size" variable. Processed data are saved to new files with the same name as the source file with the "LASCA" suffix.

specklepy's People

Contributors

ppieczywek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zamanashiq3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.