0

i am working extracting data from images using Matlab, i use the function im2bw in gray images for use later bwlabel but the threshold doesn't work in all images, by that the images gain noise and the data obtained isn't representative. How i can configure the threshold for evitate that problem?the function graytresh doesn't give a good threshold, exist any other method to fix the problem? I work with a lot of images (more of ten thousand sometimes) and i can't run one by one. The images are of fishes swimming and i need to be careful. Thanks for read my problem!.

I use graytresh in images bw like this https://i.stack.imgur.com/kPtPc.jpg -Sometimes the distortion on images are too much dropbox with images https://www.dropbox.com/sh/xve7oe84xcfj9yt/AACA0dYrK_m7o8Oie0KWWR-2a?dl=0 starter images, bin images with distortion and bw images

JVidal
  • 3
  • 6
  • Try `otsuthresh`. – NKN Sep 28 '16 at 19:50
  • @NKN how is `otsuthresh` different from `graythresh`? Both use Otsu's method, so the result will probably be exactly the same. – hbaderts Sep 28 '16 at 20:21
  • @JVidal So are you using the same threshold for all images? How do you find that threshold? Only on one image? – hbaderts Sep 28 '16 at 20:24
  • i use the same threshold for all images, i find one of reference using _graythresh_ in several images then i calibrate the threshold manually, generally is near of the threshold _graytresh_. The images are similar and the threshold ideal for every image are close. – JVidal Sep 29 '16 at 16:33
  • Please provide some more sample images - it is very hard to know if a method will likely work when we can only see a single image! – Mark Setchell Sep 29 '16 at 18:08
  • ok :D i will post more images in a dropbox, stackoverflow doesn't leave upload more in the post – JVidal Sep 29 '16 at 23:27
  • https://www.dropbox.com/sh/xve7oe84xcfj9yt/AACA0dYrK_m7o8Oie0KWWR-2a?dl=0 here – JVidal Sep 30 '16 at 00:52

2 Answers2

0

There are countless methods for determining binarization thresholds. It depends on the images. A general answer that works for any image cannot be given.

I suggest you pick a representative set of images and compare the results of most common thresholding methods.

It is also possible that a global threshold is not suitable at all. Also try local thresholding methods.

Read this for an extensive comparison on thresholding methods: http://pequan.lip6.fr/~bereziat/pima/2012/seuillage/sezgin04.pdf

Piglet
  • 27,501
  • 3
  • 20
  • 43
0

I had a little attempt at finding the fish, and seem to get quite good results using a normalised Green-Blue difference - this is just the difference between the Green and Blue components, normalised to the range [0,1]. The steps I use are as follows:

  • do an auto-level contrast stretch to space things out better
  • calculate the normalised Green-Blue difference, (Green-Blue)/(Green+Blue)
  • threshold at 25%

I just used ImageMagick at the command-line. It is installed on most Linux distros and is available for OSX and Windows. I am sure you can do just the same in Matlab:

convert fishy.jpg -auto-level -fx "(g-b)/(g+b)" -threshold 25% result.jpg

enter image description here

If I had 10,000 images to do, I would use GNU Parallel to get all my CPU cores working in parallel:

parallel 'convert {} -auto-level -fx "(g-b)/(g+b)" -threshold 25% results/{}' ::: fish*jpg
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432