3
$\begingroup$

I would like to take a user's hand drawn input, and filter out "noise", aka small sketches or blobs, where the user might have screwed up and accidentally touched his hand to the drawing device, or something similar.

I'm using Imagick, a PHP wrapper that wraps an image processing library that does everything short of actual, high-level blob detection. So I'm free to use convolution, erosion, dilation, and a slew of other image processing tools. I can't write blob detection in the high level PHP code because it's too slow. And before I go down a path of writing the C code using ImageMagick's API, and wrapping it in PHP, I was wondering if there's some sort of "trick" that I can do to accomplish my objective.

For instance, my initial thought would be to do an erosion on the image (in normal situations, when I think of removing noise from an image, I think to erode then dilate). But since ALL the lines in the image are just a few pixels wide, everything would disappear. Then I was considering some sort of blur so the longer lines would end up with higher intensities, then I could just threshold out the lower ones. But again, in the context of lines, I'm not sure how well that works.

I'll attach an image of increasing "blobs". I would consider the first 4 left ones as blobs that I want to remove, but then keep the 5th, the line, and the box.

Left 4 or 5 smudges bad, the rest are good.

$\endgroup$

2 Answers 2

1
$\begingroup$

You can use opening on your image http://php.net/manual/en/imagick.morphology.php with a kernel big enough to erode the small objects

$\endgroup$
2
  • $\begingroup$ Ah yes good suggestion. But alas this isn't built into the PHP "Imagick" tools. Implementing their C API into a PHP method is the last route I want to go down. $\endgroup$
    – justynnuff
    Sep 3, 2016 at 6:48
  • $\begingroup$ I wrote a new suggestion $\endgroup$ Sep 3, 2016 at 22:17
1
$\begingroup$

Why don't you just count the numbers of pixels in each connected structure (by an appropriate definition of connected), and set a threshold on the number of pixels? If it is e.g. below 10 px, it is probably something to be discarded.

Only immanent draw back: dot, e.g. on the letter i or as interpunctation could also be dismissed. But it depends on your application.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.