Search for partially matching pattern in an image - image-processing

Consider the following problem of locating a 2d pattern inside an image (0-255).
A match is said to be found at (x, y) if most of the elements of the bigger matrix (say > 50%) are in some range of the respective elements of the smaller matrix i.e
0.8*small[i][j] <= bigger[x+i][y+j] <= 1.2*smaller[i][j]
I remember this problem to be a standard problem in image searching, but couldn't recollect, neither find the exact name.
I would be very grateful if someone could figure out the name of an equivalent standard problem.
Thank you in advance.

I thought it might have been something like "moving windows" or something, so that's what I looked for. Thinking of the right name can be tricky, and with so many similar methods, finding the actual one you want can get hard. Glad I could help you out.
Anyway, it's template matching.

In the context of video compression (as opposed to image recognition) this is called block matching: http://en.wikipedia.org/wiki/Block-matching_algorithm

Related

Convolution that uniquely identifies all possible spatial patterns

I'm working on a problem that requires searching for some unique 3x3 patterns in binary images. My current method is to do a convolution with a kernel where each value is a different power of two, essentially producing a 9-bit number for each pixel. This is working for me, and I can search for my patterns quickly by simply checking for the corresponding numbers.
I have a couple questions:
Is there a name for this kernel or method? I cannot find any
reference to one like it, but I don't exactly know what to call it.
Is there another way to go about this? I get skeptical of my methods when I don't see anyone else doing it :)

DL4J - When using a ComputationGraph, is it possible to get the Class labels from it?

I saw how to do this from a DataSet object, and I saw a setLabel method, and I saw a getLabelMaskArrays, but none of these are what I'm looking for.
Am I just blind or is there not a way?
Thanks
Masking is for variable length time series in RNNs. Most of the time you don't need it. Our built in sequence dataset iterators also tend to handle these cases. For more details see our rnn page: https://deeplearning4j.org/usingrnns

Deap: Want to know the generation that created the best individual

I'm running a genetic algorithm program and can find the best individual at the end of the run (hof[0]), but i want to know which generation produced it. Is there any attributes of hof[0] that will help print the individual and the generation that created it.
I tried looking at the manuals and Google for answers but could not find it anywhere.
I also couldn't find a list of the attributes of individuals that I could print. Can someone point to the right link and documentation to that.
Thanks
This deap post suggest tracking the logbook, or explicitly adding the generation to the individual along with fitness:
https://groups.google.com/g/deap-users/c/r7fZbMwHg3I/m/BAzHh2ogBAAJ
For the latter:
If you are working with the algo locally(recommended if working beyond a tutorial as something always comes up like adding plotting or this very questions) then you can modify the fitness update line to resemble:
fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
for ind, fit in zip(invalid_ind, fitnesses):
ind.fitness.values = fit
ind.generation = gen # now we can: print(hof[0].gen)
if halloffame is not None:
halloffame.update(population)
There is no built in way to do this (yet/to the best of my knowledge), and implementing this so would probably be quite a large task. The simplest of which (simplest in thought, not in implementation) would be to change the individual to be a tuple, where tup[0] is the individual and tup[1] is the generation it was produced in, or something similar.
If you're looking for a hacky way, you could maybe try writing the children of each generation to a text file and cross-checking your final solution with the text file; but other than that I'm not sure.
You could always try posting on their Google Group, though it can take a couple of days for a reply.
Good luck!

How to add a point to a path in Raphael (SVG)

I'm in a situation where I have a number of paths on the screen, updated several times per seconds. they are extremely simple line paths, each of them is just a simple line on canvas.
I need an efficient way of updating the paths. At the moment, I'm retrieving the path string for each of them, add 'L xx xx', and redraw. It's fine with a small number of lines, but the performance is really bad once the frequency (or the number of paths) increases.
so, the real question is - does Raphael provide a method that would just 'add a point to the path'?
I'm very new to vectors, not to mention Raphael and svg.
Would be grateful for any help
Thanks
K
I wonder what your doing ;)
Try just Maintenon the updated path and use the "path" attribute on the path
I would be interested to hear if the performance improves
Also you might like to visit my site and play with the demo there for lovely rounded paths
http://irunmywebsite.com/raphael/additionalhelp.php?v=2
Look at the technique Catmull Rom Curves it might inspire...
EXCUSE BARE LINKS AND SPELLING iPod!

What are some good methods to find the "relatedness" of two bodies of text?

Here's the problem -- I have a few thousand small text snippets, anywhere from a few words to a few sentences - the largest snippet is about 2k on disk. I want to be able to compare each to each, and calculate a relatedness factor so that I can show users related information.
What are some good ways to do this? Are there known algorithms for doing this that are any good, are there any GPL'd solutions, etc?
I don't need this to run in realtime, as I can precalculate everything. I'm more concerned with getting good results than runtime.
I just thought I would ask the Stack Overflow community before going and writing my own thing. There HAVE to be people out there who have found good solutions to this before.
These articles on semantic relatedness and semantic similarity may be helpful. And this SO question about Latent Semantic Analysis.
You could also look into Soundex for words that "sound alike" phonetically.
I've never used it, but you might want to look into Levenshtein distance
Jeff talked about something like this on the pod cast to find the Related questions listed on the right side here. (in podcast 32)
One big tip was to remove all common words, like "the" "and" "this" etc. This will leave you with more meaningful words to compare.
And here is a similar question Is there an algorithm that tells the semantic similarity of two phrases
This is quite doable for reasonable large texts, however harder for smaller texts.
I did it once like this, and it worked pretty well:
Filter all "general" words (like a, an, the, in, etc...) (filters about 10-30% of the words)
Count the frequencies of the remaining words, store the top x of most frequent words, these are your topics.
As an extra step you can create groups of 2/3/4 subsequent words and compare them with the groups in other texts. I used it as a measure for plagerism.
See Manning and Raghavan course notes about MinHashing and searching for similar items, and a C#(?) version. I believe the techniques come from Ullman and Motwani's research.
This book may be relevant.
Edit: here is a related SO question
Phonetic algorithms
The article, Beyond SoundEx - Functions for Fuzzy Searching in MS SQL Server, shows how to install and use the SimMetrics library into SQL Server. This library lets you find relative similarity between strings and includes numerous algorithms.
I ended up mostly using Jaro Winkler to match on names. Here's more information where I asked about matching names on SO: Matching records based on Person Name
A few algorithms based on Levenshtein Distance are also available in the SimMetric library and would probably be useful in your application.

Resources