-1

I have a question and hope that you can help me.

I need to count objects in a bakery production line. Unfortunately this is not ideal for image processing. The machine has to be accessible, people cast shadows walking by and working at the machine. The lighting can vary slightly depending on which ceiling light is on and also depending on the daylight.

But there is fairly good contrast between the objects and the transportation belt.

Usually the image looks similar to this:

enter image description here

This is part of a retrofit for a production line. People need to work exactly where the camera is. What you see are about 1 cm wide lines of dough. Sometimes they tear apart and clutter the machine after some minutes. And this is the crucial place, here you the cluttering happens, it is where people fix is and the only place where you can see the dough before it enters the oven.

The center of the image is brighter, especially the right quarter is usually darker, can be even more that it is in the image.

So far my approach is

  • Gaussian Blur
  • Thresholding
  • Morphological Opening (several times, stupid, idempotent)
  • Find Contours

I could not find a threshold manually that is robost and Otsu's threshold is also not fixing the problem. The threshold is always messing up the right quarter. The other part of the image works like a charm.

Installing an additional light might fix the problem, but that is not likely to happen anytime soon. I tried to brighten up the right side with a flashlight and it works like a charm then. :)

I also tried "normal" Histogram Equalization and CLAHE, but without success. Also the suggestions from Automatic contrast and brightness adjustment of a color photo of a sheet of paper with OpenCV, also no improvement.

So, the task looks rather simple to me, but I am out of luck and there is probably a simple solution that I am missing.

Ideas?

Edit:

remove gradient of a image without a comparison image describes the bandpass / lowpass filtering as mentioned in the comments (big median blur or big gaussian blur).

Joe
  • 6,758
  • 2
  • 26
  • 47
  • 3
    bandpass. run a big median blur or gaussian blur. **subtract** that. you're left with the "signal" (mind the negative values). of all the other methods mentioned, only CLAHE goes in the same direction (the key is "locally adaptive"), but you have to use it right. – Christoph Rackwitz Dec 11 '21 at 19:08
  • 1
    Often it is easier to control the lighting by installing a physical tunnel which has its own lighting inside and prevents environment light to reach your cameras. – Micka Dec 11 '21 at 19:15
  • Like here... https://stackoverflow.com/a/27893051/2836621 – Mark Setchell Dec 11 '21 at 19:43
  • “Morphological Opening (several times)” is surprising because: (1) the opening is idempotent, meaning that applying the same operation (with same structuring element) a second time will not further change the image, and (2) the opening is absorbing, meaning that a sequence of opening with different structuring elements can be replaced by a single opening if the structuring elements “fit” inside each other (which is often the case). There are very few cases where it is interesting to apply more than one opening at the time, unless you interleave other operators. – Cris Luengo Dec 11 '21 at 21:25
  • 1
    @Micka, I completely second that. This is part of a retrofit for a production line. People need to work exactly where the camera is. What you see are about 1 cm wide lines of dough. Sometimes they tear apart and clutter the machine after some minutes. And this is the crucial spot, here the cluttering happens, it is where people fix it and the only place where you can see the dough before it enters the oven. We put the request for probably an LED strip in with the technician, but that might be months before this is happening, also maybe not needed if I can solve it with the software. – Joe Dec 12 '21 at 07:02
  • I guess it will be very hard to tune it in a way that it will always work, even with currently unknown environmental effects. You will probably observe new challenges over a long period of time. Which however can be nice for your development team since you can get additional follow-up projects. Best changes will probably have DNNs but you will need a lot of data and a strong processing device – Micka Dec 12 '21 at 08:53

1 Answers1

2

Otsu works like a charm on your image (value 158), I wonder why you claim that "Otsu's threshold is also not fixing the problem."

enter image description here

Anyway, for worse images, the solution is adaptive thresholding, with a size larger than those quadrilaterals.

  • Thanks for you reply, will try this. Yes, for that image it works. Should you apply Otsu before or after a small Gaussian blur (5,5)? And is there a rule of thumb for how much larger than the quadrilaterals the regions for the adaptive thresholding should be? 3 times? 10 times? Or is more of trial and error? – Joe Dec 12 '21 at 07:18
  • @joe: There is no point blurring, why do you want to do that ? –  Dec 12 '21 at 15:14
  • Sometimes there are crumbs on the transport belt. My thought was to smear them so they turn up below the threshold. Would opening or eroding twice be a better idea? – Joe Dec 12 '21 at 16:09
  • Show sample pictures, I am no diviner. –  Dec 12 '21 at 16:23
  • I don't have any at the moment, but the picture in the question, between the second and third line from the left shows a rather small one. But they can be up to about 5 times that size and have the same brightness as the lines. – Joe Dec 12 '21 at 18:18