Removing elements with a Single Colour from an Image

Viewed 303

I'm working on image pre-processing in R, and for that I use the package magick. While doing my work I encountered myself in a situation that I'm unable to solve. I've an image which consists mostly in green tones, but there are some elemnts that are in black, and those are the one which I want.

The main question is: Is there a way to use magick to remove everything that's not black?

For example, I've a (fake) brazilian identity card signature in the image below. And I just want the signature, without the background.

enter image description here

I ran the code below on the image above.

library(magick)

assinatura = img %>% 
  image_crop("4000x100+20+210")

assinatura

The result of the code is this one.

image of a ID card with zoom in the signature field. the signature is in black, and the background is green.

0 Answers
Related