Finding multiple subimages in large image to decrypt a secret message

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
TravelingGeek
Posts: 4
Joined: 2017-01-25T14:05:44-07:00
Authentication code: 1151

Finding multiple subimages in large image to decrypt a secret message

Post by TravelingGeek »

I'm trying to automatically decode a Dancing Man cypher.
The cypher uses pictures (of a dancing man) in place of characters.

For example, here is a secret message: http://i.imgur.com/fiZPoRn.jpg
This picture is an "s" http://www.dcode.fr/tools/dancing-men/images/S.png
This picture is an "t" http://www.dcode.fr/tools/dancing-men/images/T.png
etc.

Ultimately, I want to search for all of the different dancing men (characters) in the secret message and use the coordinates of where the characters are found to piece together the translation. I'm stumped on finding more than one subimage match.

I can find on occurrence of the S with this command and output:

Code: Select all

C:\WIP>compare -metric mae -subimage-search fiZPoRn.jpg s.png null: 2>&1
768.716 (0.0117298) @ 95,579
I can't work out how to find the rest of the instances of S.

All suggestions are welcome!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Finding multiple subimages in large image to decrypt a secret message

Post by fmw42 »

Save the output from compare. Then use my script maxima to locate all the matches and match coordinates. You will need to speciy some large number of matches, but then a threshold on the metric value to stop. The resulting image will have black circles in the matched locations and the coordinate will be listed to the terminal. Note my script maxima is a unix bash shell script and will not work on Window with Cygwin or Window 10 native unix system. Note there are two outputs from compare. The second one is the image of the metric scores. Bright points represent matches. You will have lots of matches, but you need to use a high threshold to get only the letter you want.

Input:
Image ...... Image

Code: Select all

compare -metric mae -subimage-search fiZPoRn.jpg s.png out.png
Image

Code: Select all

maxima -n 100 -t 98 out-1.png max.png
Image

Code: Select all

max=1 125,39 gray=64764,252,98.8235%
max=2 245,147 gray=64764,252,98.824%
max=3 155,219 gray=64764,252,98.824%
max=4 125,435 gray=64764,252,98.824%
max=5 95,579 gray=64764,252,98.824%
For my scripts, see the link below.
TravelingGeek
Posts: 4
Joined: 2017-01-25T14:05:44-07:00
Authentication code: 1151

Re: Finding multiple subimages in large image to decrypt a secret message

Post by TravelingGeek »

wow, that was quick. Exactly what I need.

I think I could also come up do a low threshold (and maybe a morphed letter) that should hit on 100% of the characters so I can also detect where I don't have good or maybe conflicting detection. That would be perfect.

I'll have to dust off my linux box and give this a whirl.

Thanks!
TravelingGeek
Posts: 4
Joined: 2017-01-25T14:05:44-07:00
Authentication code: 1151

Re: Finding multiple subimages in large image to decrypt a secret message

Post by TravelingGeek »

Limited success on this so far.

First off, I am running the Windows 10 ubuntu (beta) instead of native linux. (surprisingly easy to setup)

When I run your script, I find the first subimage and then get errors on subsequent searches. Here's the command I used and the results:

Code: Select all

travelinggeek@FIERY:/mnt/c/WIP$ ./maxima -n 100 -t 98 ./results-1.png all_s.png
max=1 125,39 gray=64764,252,98.8235%
max=2  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
max=3  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
max=4  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
max=5  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
max=6  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
max=7  gray=64764,252,98.8235%
convert.im6: non-conforming drawing primitive definition `,' @ error/draw.c/DrawImage/3160.
The output file (all_s.png) had just one black dot.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Finding multiple subimages in large image to decrypt a secret message

Post by fmw42 »

Have you changed the name of IM's convert? I am not sure I understand the convert.im6? Have you set up the unix environment as in my pointers on my home page? Have you followed all the pointers especially about telling the script where to find IM?

The messages are about the drawing from -draw. Seems not to like the comma in the x,y coordinates or the ellipse radii. I am not sure what is the problem. Try specifying -r 5 and see if that helps.

This is the probably the first time anyone has tried to run my script from Windows 10 unix environment. So some kinks may need to be worked. I will try to help, but I do not use Windows and so have no way to test myself.

What version of Imagemagick are you running?

Does your Windows unix have all the usual unix commands such as tr, cut, sed, tail, expr, etc

If anyone else is using Windows 10 Unix, can you test this script and images and see if you have the same issue?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Finding multiple subimages in large image to decrypt a secret message

Post by snibgo »

I don't use Windows 10 and Microsoft's bash. On Windows 8.1 and Cygwin bash, with Fred's input, it works fine:

Code: Select all

f:\web\im>bash ./maxima.sh -n 100 -t 98 out-1.png m.png
max=1 125,39 gray=64764,252,98.8235%
max=2 245,147 gray=64764,252,98.824%
max=3 155,219 gray=64764,252,98.824%
max=4 125,435 gray=64764,252,98.824%
max=5 95,579 gray=64764,252,98.824%
snibgo's IM pages: im.snibgo.com
TravelingGeek
Posts: 4
Joined: 2017-01-25T14:05:44-07:00
Authentication code: 1151

Re: Finding multiple subimages in large image to decrypt a secret message

Post by TravelingGeek »

Ok, Fred... other than some very distant and limited experience with SysV a couple of decades ago, I'm mostly a linux noob.

I have imagemagick 7 installed on windows, but the ubuntu version is:

Code: Select all

travelinggeek@FIERY:~$ convert -version
Version: ImageMagick 6.7.7-10 2016-11-29 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
I installed via apt-get but had to follow up with an apt-get -f install to get the dependencies.

It seems i've got all the standard unix commands. All of the ones you suggested worked.

I ran it with the -r 5 and got the same output as before.

Thanks for working through this with me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Finding multiple subimages in large image to decrypt a secret message

Post by fmw42 »

If using IM 6.7.7.10, that could be the issue. It is very old and some of the code I use has IM functions that are newer. However, I had put in some backward compatible code for earlier versions. Perhaps there is a mistake or your version is too old. Also IM 6.7.7.10 was during a major change in IM. If you can install a more current version that might cure the issue.

But I will work with you offline to create a version of the script that will have some debug statements and we can see what we learn.

I, too, would like to be sure my scripts do work with Window 10 unix.
Post Reply