how remove date-time stamp from jpg photo?

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?".
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

how remove date-time stamp from jpg photo?

Post by Rob Rutten »

The Canon PowerShot D20 camera of a friend added a yellow banner specifying date and time in the lower right
corner of his .jpg photographs. Is there a command-line convert command to remove these? Perhaps by removing
that particular yellow color in a subframe box?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how remove date-time stamp from jpg photo?

Post by snibgo »

Those pixels are now yellow. You can change them to any colour you want, for example by drawing a rectangle, or using "-opaque" to change just that colour.

Or you could make those pixels transparent, and use one of a number of methods that guess what the pixels should be.
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: how remove date-time stamp from jpg photo?

Post by fmw42 »

Something like this might work, if the text were made black

viewtopic.php?p=41498#p41498
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

To fmw42: Dear mastermagician Fred - the duck is example is impressive! In my case the date stamp is a particular yellow color with black
borders so now my question is how to identify that color and make it black. In hope that you may wish to try your mastermagick wand
I put a sample image temporarily at http://www.staff.science.uu.nl/~rutte10 ... G_2540.jpg.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how remove date-time stamp from jpg photo?

Post by snibgo »

I expect the date caption is always in the same place. I define a region, and make a load of colours transparent.

Image

Code: Select all

%IM%convert img_2540.jpg -alpha opaque -region 970x110+2780+2525 -fuzz 10% -transparent black -transparent #fba420 -transparent #c08000  -transparent #b1832d -transparent #b15000 -transparent #ad4e00 -transparent #731e00 -transparent #805000 -transparent #402800 -transparent #2d0000 c.png
Then I try two techniques to fill the holes. One is a repeated resize of 1/1.1, about 90%. (This gives a better quality than the usual 1/2, or 50%.)

Code: Select all

%IM%convert ^
  %INFILE% ^
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
( +clone -resize 90.9091% ) 
  -layers RemoveDups ^
  -filter Gaussian -resize "%WW%x%HH%^!" ^
  -background None ^
  -compose DstOver -layers merge ^
  -alpha opaque ^
  %OUTFILE%
Image

Then my own process module.

Code: Select all

%IMDEV%convert c.png -process 'fillholes wr 3 lsr 50 v' cv.png
Image
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: how remove date-time stamp from jpg photo?

Post by fmw42 »

snibgo's second method is the best way, but requires his special software. I hope in a near future release of IM that his (inpainting) code will be implemented in Imagemagick. I will recommend that as the next enhancement after what is being worked on now.

To replace a color with another, you can do

convert image -fuzz XX% -fill black -opaque orange result

Measure your orange color as rgb or hex as closely as you can and use that rather than orange. Also use as small an XX% as you can to replace near colors if your orange color is not a constant value. All these methods assume that orange is isolated to the text and does not appear elsewhere in large quantities in your image.
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

Sibgo's second example looks perfect but the warnings on his website indeed imply I should wait for incorporation in imagemagick (I don't
speak windows or c and bat > tcsh also seems far too involved for me).

I don't know how he found all the colors by which he made the date-time stamp transparent ("how identify RGB of a pixel" was another search giving windows but no linux solution) but using them in:

convert IMG_2540.jpg -region 970x110+2780+2525 -fuzz 10% -fill black -opaque black -opaque #fba420 -opaque #c08000 -opaque #b1832d -opaque #b15000 -opaque #ad4e00 -opaque #731e00 -opaque #805000 -opaque #402800 -opaque #2d0000 test2.png

indeed made the date-time stamp black in test2.png. But it doesn't go away with:

morphology -m grayscale -t close -i 2 test2.png test2_close.png

and so I am stuck now at that....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how remove date-time stamp from jpg photo?

Post by fmw42 »

I tried the bottom hat and other similar techniques, but they do not work well with such large fonts. I would suggest you use snibgo's first method.

I suspect he measured the colors in and around the orange and black outline to make transparent. Then he just used

Code: Select all

-transparent somecolor 
repeatedly on every color needed to make the whole text transparent. There are tools available that will allow you to read a color at a given pixels. See for example GIMP.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how remove date-time stamp from jpg photo?

Post by snibgo »

Yes, I used Gimp to find the two main colours (black, and an orange #fba420). I guessed at some intermediate colours: #c08000 etc. That left some pixels opaque, so I added more entries until they were all transparent.

You may find that the same set of colours works for all your photos, in the same way that the same "-region" probably works for all your photos. If either of these isn't true, the job becomes trickier.
snibgo's IM pages: im.snibgo.com
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

Dear experts, I am very grateful for your efforts on my behalf! I already tried snibgo's first method but didn't get a working script
using csh (the only I know) for the repeated (+clone -resize) convert entries. Frankly, the -clone option explanation re parentheses is also beyond me... Would you be willing to spell out a csh version?
I indeed hope that a method working for this sample picture will also work for all 340 others from that camera. The labels indeed look the same
(position and color).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how remove date-time stamp from jpg photo?

Post by snibgo »

Sorry, I don't know csh. With bash, you need a backslash \ at the end of each line and before each parenthesis: \( \).

I've thought of a new method for doing this, which might be very effective and fairly fast (the same cloning principle as my "fillholes" module, but much faster):

1. Take the image with holes.

2. Chop it into small rectangles, such that each small rectangle has both opaque and transparent pixels.

3. For each small rectangle:

3a. Search for it in the rest of the image, or a portion of it, that is outside the region. This is a "wildcard" search, where transparent pixels match anything. This gives us the "closest" replacement for each small rectangle.

3b. Put the replacements in their correct positions behind the image with holes, which fills the holes.

As a variation of this: the small rectangles overlap each other, so the replacements also overlap. Assemble them with minimum error boundary cut.

I've written the code for minimum error boundary cut, and the "wildcard" search. Now I just need to glue it together.
snibgo's IM pages: im.snibgo.com
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

Dear snibgo - again many thanks for your effort!

I tried my hand at bash but don't get the script working. I put it (fillholes) in http://www.staff.science.uu.nl/~rutte10 ... termagick/
together with testtrans.png made with your transform-to-transparent convert command.

The new method sounds clever! Maybe something good for mankind will come out of this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how remove date-time stamp from jpg photo?

Post by snibgo »

For "%WW%x%HH%!", put the dimensions of your image, for example "3000x2000!".
snibgo's IM pages: im.snibgo.com
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

Thanks, should have seen that. But it still balks:
fillholes: line 92: -layers: command not found
and similar for the rest of the tail lines if I comment them out one by one. Replaced at my site. Apology I am analphabetic in these matters.
Rob Rutten
Posts: 9
Joined: 2015-11-06T02:01:51-07:00
Authentication code: 1151

Re: how remove date-time stamp from jpg photo?

Post by Rob Rutten »

Hurrah! I converted the not-working bash to a csh script in which I concatenated all lines to one and it works! I put it also on my site.
Thanks!
Post Reply