This repository contains a Python script for image processing tasks. The script processes a set of JPG images and performs color analysis on them using ImageMagick.
Before running the script, ensure that the following dependencies are installed:
- Python
- ImageMagick
To use this script, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/repository-name.git
-
Navigate to the cloned repository:
cd repository-name
-
Install the required dependencies:
pip install -r requirements.txt
-
Make sure the required images are present in the repository directory.
-
Open the Python script
script.py
and ensure that the correct image filenames are specified in thedict_samples
dictionary. -
Run the script:
python script.py
This will generate a set of bash scripts in the
scripts
directory, each corresponding to an individual image. -
Optionally, you can check whether the required images were taken into consideration by uncommenting the line
#print dict_samples
in the script. -
Once the script has finished running, you can execute the generated bash scripts individually to perform color analysis on each image.
-
The script uses ImageMagick's
convert
command to process the images. Make sure that ImageMagick is properly installed and accessible from the command line. -
The color analysis is performed for two colors, "red" and "yellow". You can modify the colors or add more colors as per your requirements by editing the bash script template in the
text
variable. -
The bash scripts generated by the script are saved in the
scripts
directory with the naming conventionresult1.sh
,result2.sh
, and so on, corresponding to each image. -
The script assumes that the images are in JPG format and are located in the same directory as the script. If your images are in a different format or location, make sure to modify the script accordingly.
-
Feel free to customize the script to suit your specific image processing needs.
This project is licensed under the MIT License.
A step by step guide to count stomata using Linux (Machine Learning)
Disclaimer : Every file is given separately to cross check the results, before proceeding to the next step. The below codes are tested on Ubuntu 18.04.5 LTS using bash, Python2.7 or ImageMagick.
A. Installation
Install conda as instructed by https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html.
Install ImageMagick as instructed by https://anaconda.org/conda-forge/imagemagick. By default, it will install all the dependencies along with the relavant libraries.
Install python using conda and then use pip, to install module/packages required - sys, os, glob.
Either png or jpg format are recommended. Since the image captured by microscope must be edited/measured using Microsoft paint 2D, if you save the file in another format like TIF, then you can change to above mentioned preferred format.
B. Drawing a sticker/dots over the leaf
location = /home/username/Documents
Steps to add dots/stickers to the image
-
Open the file in the PAINT 3D and start painting as mentioned below.
-
Select option -> 2D Shapes -> round shape -> Both line type and fill should be red for stomata -> similarly do for the pavement cells using yellow color -> save image in a new folder.
Example files are attached in the rar format
Save image file with the ending "dots.png" or "dots.jpg" (file Extension and name ending is much more important), since the next python file will look for this and start creating bash files. Warning: You should not work with original file received taken from microscope.
C. Create bash files for every images
-
Run command to create a new_folder/directory
mkdir scripts
Saved location = /home/username/Documents/scripts
-
Run the below command to create bash files separately for all the images
python2.7 create_bash_files.py
location = Saved location = /home/username/Documents
If you want to redirect all the output to a text file then use "python2.7 create_bash_files.py >created_text.txt".
Result file should be in the file -> /home/username/Documents/created_text.txt
D. Counting the cells
Run the command "python2.7 count_stomata.sh >final_count.txt".
Result file should be in the file -> /home/username/Documents/final_count.txt
some of the useful links
https://stackoverflow.com/questions/44439555/count-colored-dots-in-image#comment75876873_44439555