2

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.

John P. S.
  • 367
  • 3
  • 17
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. When it's "removed" what do you want it replaced with? When you say black, do you mean it's like a proper hex #000000 value? – MrFlick May 12 '20 at 23:46
  • @MrFlick I edited the image with the desired image. Unfortunately I don't know how to give you a Reprex of that since I don't have the desired output. – John P. S. May 13 '20 at 00:16
  • 2
    Your black is not true black. Some of the green eats into the black or tints it. Also there are other near-black other areas. A finally the signature is too small and with thin lines. In command line you can do `convert id_card.png -fuzz 30% -fill white +opaque black x.png`, but you can see the signature is broken up and there are other dark areas even at the relatively large 30% fuzz value. – fmw42 May 13 '20 at 01:35
  • @fmw42 Understood. There's no other way to work around that? – John P. S. May 13 '20 at 19:59
  • 1
    Can you scan the id cards at a higher resolution? – fmw42 May 13 '20 at 20:58
  • @fmw42 I could do that, but I think I could not share a sample since they are sensitive data. – John P. S. May 14 '20 at 03:38

0 Answers0