what does it mean background at the edges

Asked by masuo on 2017-07-16

I read this document.
http://sikulix-2014.readthedocs.io/en/latest/basicinfo.html#sikulix-how-does-it-find-images-on-the-screen

I can't understand the following explanation what does it means visually.

"Depending on various aspects of the target image (mainly how much even background towards the edges in contained in the target image),"

And I read question #647444
https://answers.launchpad.net/sikuli/+question/647444

Also I can't understand the following explanation what does it means visually.

"A capture should have as little background at the edges as possible (less than 20% counted in pixels) "

Is there any visual sample?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-07-17
Last query:
2017-07-17
Last reply:
2017-07-16
Best RaiMan (raimund-hocke) said : #1

Since it is so easy, people tend to capture their images rather broadly than putting the cutting line very near around the main aspects (e.g. a button).

"towards the edges" in this case means the the edges of the captured image, an example:
- you have a button measuring 300 x 100 pixels (width x height) at the exact bounds of the button
- you capture broadly around an get an image measuring 500 x 200
- this means you have a "surrounding background towards the edges" of top/bottom each 50 pixel and left/right each 100 pixel (supposing the capturing has the button centered)

now the mentioned background-ration:
- image if interest has 300x100 = 30.000 pixels
- surrounding background is 2x300x50 + 2x200x100 = 30.000 + 40.000 = 70.000 pixels

since the search algorithm is a statistical calculation over all pixels of the captured image (see the matchTemplate() feature of OpenCV) in this case, the weight of the background is about times 2.3 to the real button pixels.
So if only a few pixels in the background of the current search region differ from the situation, where the image was captured, this will influence the match score, the more the surrounding background differs around the button borders.

My experience is that the surrounding background should be less then 20% of the total image pixels.
In this case this maximum would be about 7.000 pixels, meaning that you have to capture as near as about 4 pixels around the button edges, which you would normally only do, if you knew about the possible problems.

if interested - these are the formulas:
- size of image of interest: imgInterest
- size of captured image: imgComplete

- the challenge:
imgInterest = 0.8 x imgComplete

- the max background
maxBack = (5 * imgInterest) / 4 - imgInterest

- supposing even pixels around image of interest (edgePixels):
(2 * imageInterestWidth + 2 * imageInterestHeight) * edgePixels + 4 * edgePixels * edgePixels = maxBack

this can be solved according to the binomial:
a * a + 2 * a * b + b * b = someValue

... and this is a script to calculate the edge pixels
import math
imgInterestW = 300
imgInterestH = 100
imgInterest = imgInterestW * imgInterestH
maxBack = 5 * imgInterest / 4 - imgInterest
edge = 0 # the edge pixels
# the binomial formula aspects
# a * a + 2 * a * b + b * b = someValue
# (2 * imgInterestWidth + 2 * imgInterestHeight) * edge + 4 * edge * edge = maxBack
# binom2b = (2 * imgInterestW + 2 * imgInterestH)
binomb = imgInterestW + imgInterestH
binombSq = binomb * binomb
# binom2b * edge + 4 * edge * edge = maxBack
# binombSq + binom2b * edge + 4 * edge * edge = maxBack + binombSq
# (binomb + 2 * edge) * (binomb + 2 * edge) = maxBack + binombSq
# (binomb + 2 * edge) = math.sqrt(maxBack + binombSq)
edge = (math.sqrt(maxBack + binombSq) - binomb) / 2

print "for an image of interest having %d x %d (width x hight)" % (imgInterestW, imgInterestH)
print "the capture should be maximum %d pixels around" % edge

masuo (masuo-ohara) said : #2

Thank you for detailed explanation.

When I capture button image, I put the cutting line very near around the button. So I could not understand "surrounding background towards the edges".
Now I understand.
In short, we should not contain images that may change, when capture target image.

I have tried to find any differences in result with regard to "the edge of the image". And I have noticed a relationship between the edge of the image and the search area. Although it may not be a good expression, the edge of the image must be included in the search area.

I uploaded a concrete example.
http://masuo.doorblog.jp/archives/51793748.html

masuo (masuo-ohara) said : #3

Thanks RaiMan, that solved my question.

RaiMan (raimund-hocke) said : #4

Did not know your great blog until now - impressive - good work.
... though I have to live with the english google translation ;-)

masuo (masuo-ohara) said : #5

Thank you RaiMan for visiting to my blog.
Did you notice a translation switch that is upper right top of the blog page?

RaiMan (raimund-hocke) said : #6

--- Did you notice a translation switch that is upper right top of the blog page?
Yes of course I did ;-) Otherwise I did not have any chance, to read anything at all ;-)

in my comment #4:
... though I have to live with the english google translation ;-)
Google translation feature has developed rather well over the last years, but it is still on a low level and in many cases produces funny results, that might lead to misunderstanding.

masuo (masuo-ohara) said : #7

You are right.
I chose an easy way. (^_^;)