delete a line or two..

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

delete a line or two..

Post by toshog »

hi all...

can somebody briefly explain what is the fastest way to delete the lines around the date and time in this image using the command line:
Image

thanks...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: delete a line or two..

Post by snibgo »

If you know the coordinates of the ends, IM could paint quickly over them. Finding those coordinates in the general case wouldn't be trivial.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: delete a line or two..

Post by fmw42 »

if this is a one-time thing, then it would be best to use a gui tool such as Photoshop or GIMP to paint over the lines with white.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: delete a line or two..

Post by toshog »

snibgo wrote:Finding those coordinates in the general case wouldn't be trivial.
aware. thanks. any idea of how would that work?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: delete a line or two..

Post by snibgo »

You'd have to examine a few examples to determine commonality. For example:

- Trim off surrounding white space.
- Is the date/time always in approximately the same position? Then crop everthing else away.
- Are the lines usually/always thicker than the letters? Then morphology erode will erode them first.
- Use "compare" to look for large patches of white space. This gives x-coordinates where the lines are not present.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: delete a line or two..

Post by fmw42 »

I tried morphology with no success.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: delete a line or two..

Post by toshog »

thanks snibgo....

date and time a kinda in the same place but not really. sometimes not too close.
actually the lines are thinner then the letters.

i'll play with the compare you are mentioning although it seems to me like a long shot...

is there a way for imagemagick to detect anything else that is not a letter and that way get it's coordinates?

thanks...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: delete a line or two..

Post by snibgo »

For this particular image, moo.jpg, IM can readily find the horiontal lines. Use a search pattern (say) 10 pixels wide, and six high. Make lines 0, 1, 4 and 5 white; lines 2 and 3 black.

compare -metric RMSE moo.jpg search.png found.png

Threshold found.jpg [edit: I mean found.png] about 66%, and it will be white where the search was found (ie the tops of the roughly horizontal lines) and black otherwise.

The vertical lines on moo.jpg aren't clean, so that technique wouldn't work there. Instead, you could find the limits of the white lines in found.png, and just assume the vertical lines are between those.
Last edited by snibgo on 2010-04-15T15:33:29-07:00, edited 1 time in total.
snibgo's IM pages: im.snibgo.com
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: delete a line or two..

Post by toshog »

snibgo wrote:compare -metric RMSE moo.jpg search.png found.png
let me see if i understand this correctly. i need to create a search.png that has the same lines as they appear in the image? and then compare the two images to basically "cancel" out the lines in the main image?

if this is true i can try to do that. as a proof of concept but since these images would be scanned and maybe coming off cameras the box's dimensions may vary. maybe not drastically but enough to trow the comparison off..

does this make sense?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: delete a line or two..

Post by snibgo »

Yes, that's it. That's why you need to find commonalities between source images. "compare" will find "similar" matches, hence my cut-off at 66% will finds lines that are shorter than 10 pixels, or are slightly diagonal, etc. Reduce that number to far, and you will get false positives.

If the input images vary greatly, you might need to change your strategy (eg search for diagonal or vertical lines).
snibgo's IM pages: im.snibgo.com
Post Reply