bugcount


Namebugcount JSON
Version 0.0.11 PyPI version JSON
download
home_pagehttps://github.com/y-takefuji/counting-for-entomologists
SummaryA package for counting BLOB objects
upload_time2024-04-22 08:37:41
maintainerNone
docs_urlNone
authoryoshiyasu takefuji
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # A new tool for counting the number of small objects.
[![Open in Code Ocean](https://codeocean.com/codeocean-assets/badge/open-in-code-ocean.svg)](https://codeocean.com/capsule/dc7d4ef4-d838-467d-ab87-828e54dbd580/tree)

DOI: https://doi.org/10.24433/CO.4823110.v1

This is under review.

bugcount is a useful tool for entomologists to count the number of bugs.

bugcount has been downloaded by 12155 users worldwide as of July 21, 2023.

# How to install this package:
$ pip install bugcount

$ pip install bugcount --force-reinstall --no-cache-dir --no-binary :all:

You need to update the opencv-python library to the latest version:

$ pip install -U opencv-python --user

# How to use this bugcount:
In command terminal, type bugcount file-name or bugcount file-name Canny-coeffient

$ bugcount filename

or

You must download pillbug.png file:

https://github.com/y-takefuji/counting-for-entomologists/raw/main/pillbug.png

$ bugcount pillbug.png

<img src="https://github.com/y-takefuji/counting-for-entomologists/raw/main/r75.png" width=270 height=275>

$ bugcount filename Canny-coeffient

Default Canny-coeffient is 75.

or 

$ bugcount pillbug.png 10

<img src="https://github.com/y-takefuji/counting-for-entomologists/raw/main/r10.png" width=270 height=275>

$ bugcount pillbug.png 100

<img src="https://github.com/y-takefuji/counting-for-entomologists/raw/main/r100.png" width=270 height=275>

pillbug.png file is a target image for counting the number of bugs. 

The smaller Canny coeffient, the more minute objects can be detected.

# Detailed program of bugcount.py and pillbug_count.py
bugcount has been downloaded by 5513 users worldwide.
<pre>
This new repository introduces a new tool on object counting for entomologists.

bugcount.py or bugcount is an executable pypi version program while 
pillbug_count.py is a modifiable program for researchers. 

Counting the number of dead bugs or insect corpses on a plane is tedius 
and a very time-consuming task. 

The proposed approach is based on BLOB. The term "BLOB" stands for 
"Binary Large OBject".

The proposed algorithm is based on the state-of-the-art Canny edge 
detection and Gaussian Blur function using OpenCV library in Python.

Canny edge detection is used for creating blobs and Gaussian Blur function 
for eliminating noises.

Without machine learning, the Python program (pillbug_count.py) can count 
the number of objects in a picture with a uniform colored background.

The conventional machine learning needs to collect and annotate a variety 
of images which is a time-consuming task.

Since I am one of pioneers of neural computing, I know better than anyone 
that collecting images and annotating them is tedious and a waste of time.
The citation number of the following publications is based on Google Scholar:
</pre>

<p>
Deep learning vs shallow learning published in IEEE COMPUTER in 1992: <a href="https://ieeexplore.ieee.org/abstract/document/144401/">Functional Link Net Computing: Theory, system Architecture and Functionalities (578 cited)</a>
<p>
First paper on channel assignment problems published in IEEE Trans. on Vehicular technology in 1992:<a href="https://ieeexplore.ieee.org/abstract/document/182594/"> A neural network parallel algorithm for channel assignment problems in cellular radio networks (349 cited )</a>
<p>
First book for neural optimization published in 1992: <a href="https://link.springer.com/book/10.1007/978-1-4615-3642-0">Neural Network Parallel Computing (324 cited)</a>
<p>
First Quiz bowl world champion in NIPS 2017: <a href="https://www.aclweb.org/anthology/K16-1025.pdf"> AI defeating human champions using Wikipedia knowledge (241 cited)</a>
<p>
First image processing in IEEE medical imaging in 1992: <a href="https://ieeexplore.ieee.org/abstract/document/141645/"> Optimization neural networks for the segmentation of magnetic resonance images (232 cited)</a>
<p>
First paper published in Science in 1989: <a href="http://science.sciencemag.org/content/245/4923/1221">A near-optimum parallel planarization algorithm, Science, pp.1221-1223 (125 cited)</a>
<p>

# How to run pillbug_count.py
 
<pre>
The target objects in a picture for counting must be separated or isolated. 
Overlapped objects can be counted as one object.

This repository shows how to use a Python program (pillbug_count.py) 
for novice users to automatically count the number of dead bugs or 
the number of insect corpses on a plane for entomologists.

In order to run pillbug_count.py, you should see the following repository 
for installing the necessary libraries:
<a href="https://github.com/y-takefuji/python-novice"> How to install and use libraries in Python for novice users</a>

1. To install an executable Python environment on your operating system 
   (Windows, Mac, Linux), 
   download a Miniconda3 .sh file or .exe file for Python3.8 or Python3.7 
   from the following site:

<a href="https://docs.conda.io/en/latest/miniconda.html">https://docs.conda.io/en/latest/miniconda.html</a>

2. Double-click Miniconda3 .exe file or run the following bash command on
   your terminal:
   $ bash Miniconda3XXX.sh
3. You need to install opencv libray, 
   type the following pip command for installation:
   $ pip install opencv-python
4. To run pillbug_count.py, type the following command for testing:
   $ python pillbug_count.py pillbug.png
</pre>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/result1.png' height=246 width=1031>

<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/result2.png' height=380 width=366>
Result: 53 objects (blobs) are found in pillbug.png file.
<pre>
Use flies.png for further testing.
$ python pillbug_count.py flies.png
</pre>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/flies.png' height=200 width=300>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/gray.png' height=200 width=300>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/blur.png' height=200 width=300>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/edges.png' height=200 width=300>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/r.png' height=200 width=300>



# You should resize an original picture for counting the number of dead bugs. And/or you should tune the Canny coefficient.


# How to tune parameters for counting in general

pillbug_count.py is shown:
<pre>
import cv2,sys
if len(sys.argv)<2: 
 print("enter figure name")
 sys.exit()

img = cv2.imread(sys.argv[1])
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5,5), 0)
blurred = cv2.GaussianBlur(blurred, (7,7), 0)

cv2.imshow("gray scale", gray)
cv2.imwrite("gray.png", gray)
cv2.imshow("blurred", blurred)
cv2.imwrite("blur.png", blurred)
coeff=int((blurred.max()-blurred.min())/100)
if coeff==1: coeff=1 
else: coeff=3
outline = cv2.Canny(blurred, 0, 75*coeff)
outline= cv2.GaussianBlur(outline, (3,3), 0)
cv2.imshow("The edges", outline)
cv2.imwrite("edges.png", outline)
(_, cnts, _) = cv2.findContours(outline, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#version4
#( cnts, _)=cv2.findContours(outline,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, cnts, -1, (0, 255, 0), 2)
cv2.putText(img,str(len(cnts)),(30,30),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2)
cv2.imshow("Result", img)
cv2.imwrite("r.png",img)
print("%i blobs" % len(cnts))
cv2.waitKey(0)
</pre>

# How to resize a picture using resize.py
<pre>
The most important tuning point lies in the size of a picture containing 
the target objects.
The following Python program can be used for resizing the picture of p.jpg
(picture size: 4032x3024). This program is tuned for a smartphone.
resize.py can convert p.jpg (size: 4032x3024) to p.png (size: 550 x 540).
The photo p.jpg was taken with my smartphone. 
resize.py is to generate the resized p.png file from p.jpg.

$ python resize.py p.jpg
</pre>
resize.py can be changed by modifying integer 756 
in img = img.resize((756,int(756*h/w)), Image.ANTIALIAS).

resize.py can rotate, resize, change brightness, image-enhance an image, 
and save the result in p.png file.
<pre>
from PIL import Image,ImageEnhance as ie
import sys

img = Image.open(sys.argv[1])
w,h=img.size
img=img.rotate(270,expand=False)
img = img.resize((756,int(756*h/w)), Image.ANTIALIAS)
img=ie.Brightness(img)
eimg=img.enhance(1.9)
eimg=eimg.crop((100,10,650,550))
eimg.save("p.png") 

</pre>
# How to tune Canny coefficient in pillbug_count.py
<pre>
You should tune and change Canny coefficient instead of "75". 
outline = cv2.Canny(blurred, 0, 75*coeff)
</pre>

# Cell counting
<pre>
In bioprocessing, reagents such as A100 can be used to disaggregate 
aggregated cell masses and automate cell counting.

</pre>

<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/cells.png' height=300 width=300>
Image source: https://bitesizebio.com/30184/quick-easy-automatic-cell-counting/

<pre>
$ bugcount cells.png

</pre>
<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/r-cells.png' height=300 width=300>



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/y-takefuji/counting-for-entomologists",
    "name": "bugcount",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "yoshiyasu takefuji",
    "author_email": "takefuji@keio.jp",
    "download_url": "https://files.pythonhosted.org/packages/8e/0f/90afd1e23aebede8e5ad19f51af9ce8e5ceff3703563bb26d5f477dc9f94/bugcount-0.0.11.tar.gz",
    "platform": null,
    "description": "# A new tool for counting the number of small objects.\n[![Open in Code Ocean](https://codeocean.com/codeocean-assets/badge/open-in-code-ocean.svg)](https://codeocean.com/capsule/dc7d4ef4-d838-467d-ab87-828e54dbd580/tree)\n\nDOI: https://doi.org/10.24433/CO.4823110.v1\n\nThis is under review.\n\nbugcount is a useful tool for entomologists to count the number of bugs.\n\nbugcount has been downloaded by 12155 users worldwide as of July 21, 2023.\n\n# How to install this package:\n$ pip install bugcount\n\n$ pip install bugcount --force-reinstall --no-cache-dir --no-binary :all:\n\nYou need to update the opencv-python library to the latest version:\n\n$ pip install -U opencv-python --user\n\n# How to use this bugcount:\nIn command terminal, type bugcount file-name or bugcount file-name Canny-coeffient\n\n$ bugcount filename\n\nor\n\nYou must download pillbug.png file:\n\nhttps://github.com/y-takefuji/counting-for-entomologists/raw/main/pillbug.png\n\n$ bugcount pillbug.png\n\n<img src=\"https://github.com/y-takefuji/counting-for-entomologists/raw/main/r75.png\" width=270 height=275>\n\n$ bugcount filename Canny-coeffient\n\nDefault Canny-coeffient is 75.\n\nor \n\n$ bugcount pillbug.png 10\n\n<img src=\"https://github.com/y-takefuji/counting-for-entomologists/raw/main/r10.png\" width=270 height=275>\n\n$ bugcount pillbug.png 100\n\n<img src=\"https://github.com/y-takefuji/counting-for-entomologists/raw/main/r100.png\" width=270 height=275>\n\npillbug.png file is a target image for counting the number of bugs. \n\nThe smaller Canny coeffient, the more minute objects can be detected.\n\n# Detailed program of bugcount.py and pillbug_count.py\nbugcount has been downloaded by 5513 users worldwide.\n<pre>\nThis new repository introduces a new tool on object counting for entomologists.\n\nbugcount.py or bugcount is an executable pypi version program while \npillbug_count.py is a modifiable program for researchers. \n\nCounting the number of dead bugs or insect corpses on a plane is tedius \nand a very time-consuming task. \n\nThe proposed approach is based on BLOB. The term \"BLOB\" stands for \n\"Binary Large OBject\".\n\nThe proposed algorithm is based on the state-of-the-art Canny edge \ndetection and Gaussian Blur function using OpenCV library in Python.\n\nCanny edge detection is used for creating blobs and Gaussian Blur function \nfor eliminating noises.\n\nWithout machine learning, the Python program (pillbug_count.py) can count \nthe number of objects in a picture with a uniform colored background.\n\nThe conventional machine learning needs to collect and annotate a variety \nof images which is a time-consuming task.\n\nSince I am one of pioneers of neural computing, I know better than anyone \nthat collecting images and annotating them is tedious and a waste of time.\nThe citation number of the following publications is based on Google Scholar:\n</pre>\n\n<p>\nDeep learning vs shallow learning published in IEEE COMPUTER in 1992: <a href=\"https://ieeexplore.ieee.org/abstract/document/144401/\">Functional Link Net Computing: Theory, system Architecture and Functionalities (578 cited)</a>\n<p>\nFirst paper on channel assignment problems published in IEEE Trans. on Vehicular technology in 1992:<a href=\"https://ieeexplore.ieee.org/abstract/document/182594/\"> A neural network parallel algorithm for channel assignment problems in cellular radio networks (349 cited )</a>\n<p>\nFirst book for neural optimization published in 1992: <a href=\"https://link.springer.com/book/10.1007/978-1-4615-3642-0\">Neural Network Parallel Computing (324 cited)</a>\n<p>\nFirst Quiz bowl world champion in NIPS 2017: <a href=\"https://www.aclweb.org/anthology/K16-1025.pdf\"> AI defeating human champions using Wikipedia knowledge (241 cited)</a>\n<p>\nFirst image processing in IEEE medical imaging in 1992: <a href=\"https://ieeexplore.ieee.org/abstract/document/141645/\"> Optimization neural networks for the segmentation of magnetic resonance images (232 cited)</a>\n<p>\nFirst paper published in Science in 1989: <a href=\"http://science.sciencemag.org/content/245/4923/1221\">A near-optimum parallel planarization algorithm, Science, pp.1221-1223 (125 cited)</a>\n<p>\n\n# How to run pillbug_count.py\n \n<pre>\nThe target objects in a picture for counting must be separated or isolated. \nOverlapped objects can be counted as one object.\n\nThis repository shows how to use a Python program (pillbug_count.py) \nfor novice users to automatically count the number of dead bugs or \nthe number of insect corpses on a plane for entomologists.\n\nIn order to run pillbug_count.py, you should see the following repository \nfor installing the necessary libraries:\n<a href=\"https://github.com/y-takefuji/python-novice\"> How to install and use libraries in Python for novice users</a>\n\n1. To install an executable Python environment on your operating system \n   (Windows, Mac, Linux), \n   download a Miniconda3 .sh file or .exe file for Python3.8 or Python3.7 \n   from the following site:\n\n<a href=\"https://docs.conda.io/en/latest/miniconda.html\">https://docs.conda.io/en/latest/miniconda.html</a>\n\n2. Double-click Miniconda3 .exe file or run the following bash command on\n   your terminal:\n   $ bash Miniconda3XXX.sh\n3. You need to install opencv libray, \n   type the following pip command for installation:\n   $ pip install opencv-python\n4. To run pillbug_count.py, type the following command for testing:\n   $ python pillbug_count.py pillbug.png\n</pre>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/result1.png' height=246 width=1031>\n\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/result2.png' height=380 width=366>\nResult: 53 objects (blobs) are found in pillbug.png file.\n<pre>\nUse flies.png for further testing.\n$ python pillbug_count.py flies.png\n</pre>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/flies.png' height=200 width=300>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/gray.png' height=200 width=300>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/blur.png' height=200 width=300>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/edges.png' height=200 width=300>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/r.png' height=200 width=300>\n\n\n\n# You should resize an original picture for counting the number of dead bugs. And/or you should tune the Canny coefficient.\n\n\n# How to tune parameters for counting in general\n\npillbug_count.py is shown:\n<pre>\nimport cv2,sys\nif len(sys.argv)<2: \n print(\"enter figure name\")\n sys.exit()\n\nimg = cv2.imread(sys.argv[1])\ngray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\nblurred = cv2.GaussianBlur(gray, (5,5), 0)\nblurred = cv2.GaussianBlur(blurred, (7,7), 0)\n\ncv2.imshow(\"gray scale\", gray)\ncv2.imwrite(\"gray.png\", gray)\ncv2.imshow(\"blurred\", blurred)\ncv2.imwrite(\"blur.png\", blurred)\ncoeff=int((blurred.max()-blurred.min())/100)\nif coeff==1: coeff=1 \nelse: coeff=3\noutline = cv2.Canny(blurred, 0, 75*coeff)\noutline= cv2.GaussianBlur(outline, (3,3), 0)\ncv2.imshow(\"The edges\", outline)\ncv2.imwrite(\"edges.png\", outline)\n(_, cnts, _) = cv2.findContours(outline, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)\n#version4\n#( cnts, _)=cv2.findContours(outline,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)\ncv2.drawContours(img, cnts, -1, (0, 255, 0), 2)\ncv2.putText(img,str(len(cnts)),(30,30),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2)\ncv2.imshow(\"Result\", img)\ncv2.imwrite(\"r.png\",img)\nprint(\"%i blobs\" % len(cnts))\ncv2.waitKey(0)\n</pre>\n\n# How to resize a picture using resize.py\n<pre>\nThe most important tuning point lies in the size of a picture containing \nthe target objects.\nThe following Python program can be used for resizing the picture of p.jpg\n(picture size: 4032x3024). This program is tuned for a smartphone.\nresize.py can convert p.jpg (size: 4032x3024) to p.png (size: 550 x 540).\nThe photo p.jpg was taken with my smartphone. \nresize.py is to generate the resized p.png file from p.jpg.\n\n$ python resize.py p.jpg\n</pre>\nresize.py can be changed by modifying integer 756 \nin img = img.resize((756,int(756*h/w)), Image.ANTIALIAS).\n\nresize.py can rotate, resize, change brightness, image-enhance an image, \nand save the result in p.png file.\n<pre>\nfrom PIL import Image,ImageEnhance as ie\nimport sys\n\nimg = Image.open(sys.argv[1])\nw,h=img.size\nimg=img.rotate(270,expand=False)\nimg = img.resize((756,int(756*h/w)), Image.ANTIALIAS)\nimg=ie.Brightness(img)\neimg=img.enhance(1.9)\neimg=eimg.crop((100,10,650,550))\neimg.save(\"p.png\") \n\n</pre>\n# How to tune Canny coefficient in pillbug_count.py\n<pre>\nYou should tune and change Canny coefficient instead of \"75\". \noutline = cv2.Canny(blurred, 0, 75*coeff)\n</pre>\n\n# Cell counting\n<pre>\nIn bioprocessing, reagents such as A100 can be used to disaggregate \naggregated cell masses and automate cell counting.\n\n</pre>\n\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/cells.png' height=300 width=300>\nImage source: https://bitesizebio.com/30184/quick-easy-automatic-cell-counting/\n\n<pre>\n$ bugcount cells.png\n\n</pre>\n<img src='https://github.com/y-takefuji/counting-for-entomologists/raw/main/r-cells.png' height=300 width=300>\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package for counting BLOB objects",
    "version": "0.0.11",
    "project_urls": {
        "Bug Tracker": "https://github.com/y-takefuji/counting-for-entomologists",
        "Homepage": "https://github.com/y-takefuji/counting-for-entomologists"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45c617c275f23a7dd952a97d9545838fffe5bbae8fe4cc8cc6ca6c8b824e4be1",
                "md5": "7c296cc1bd7a5e6ca90f18da0cc2bb68",
                "sha256": "99e923a240718690209f346de5f7cc7202759b88aa4eaad2e2de5d94b3b68815"
            },
            "downloads": -1,
            "filename": "bugcount-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7c296cc1bd7a5e6ca90f18da0cc2bb68",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5615,
            "upload_time": "2024-04-22T08:37:39",
            "upload_time_iso_8601": "2024-04-22T08:37:39.557617Z",
            "url": "https://files.pythonhosted.org/packages/45/c6/17c275f23a7dd952a97d9545838fffe5bbae8fe4cc8cc6ca6c8b824e4be1/bugcount-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e0f90afd1e23aebede8e5ad19f51af9ce8e5ceff3703563bb26d5f477dc9f94",
                "md5": "4851361c1a354c77d825865f791c1dc4",
                "sha256": "0b2f3c1ae0127165abc3a7626b2f5fe4b530273d3af444347565da222e9229ee"
            },
            "downloads": -1,
            "filename": "bugcount-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "4851361c1a354c77d825865f791c1dc4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5698,
            "upload_time": "2024-04-22T08:37:41",
            "upload_time_iso_8601": "2024-04-22T08:37:41.537824Z",
            "url": "https://files.pythonhosted.org/packages/8e/0f/90afd1e23aebede8e5ad19f51af9ce8e5ceff3703563bb26d5f477dc9f94/bugcount-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 08:37:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "y-takefuji",
    "github_project": "counting-for-entomologists",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "bugcount"
}
        
Elapsed time: 0.25650s