KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a picture like the below and I would like to count the number of bugs (continuous blobs of color/grey) that show up on it with Python. How could I do this best? I've so far looked at ImageChops, SciPy and PIL but I'm unsure what I can/should use... I think I can use ndimage.gaussian_filter() and then scipy.ndimage.measurements.label() am just not sure yet how I use latter to count my blue dots in the gaussian-ized image...... it looks something like Okay, With above image I now got this code: #! /usr/bin/python import numpy as np import scipy import pylab import pymorph import mahotas from PIL import Image import PIL.ImageOps from scipy import ndimage image = Image.open('bugs.jpg') inverted_image = PIL.ImageOps.invert(image) inverted_image.save('in_bugs.jpg') dna = mahotas.imread('in_bugs.jpg') #pylab.imshow(dna) pylab.gray() #pylab.show() T = mahotas.thresholding.otsu(dna) pylab.imshow(dna > T) #pylab.show() dnaf = ndimage.gaussian_filter(dna, 8) T = mahotas.thresholding.otsu(dnaf) pylab.imshow(dnaf > T) #pylab.show() labeled,nr_objects = ndimage.label(dnaf > T) print nr_objects pylab.imshow(labeled) pylab.jet() pylab.show() the problem is, this returns me a number of 5 which isn'rt that bad but I need to have it more accurate, I want to see two. How can I do this? Will it help to blur the image before applying the gaussian filter? Thanks for help! Ron
Tags (comma-separated)
Save Edits
Cancel