1

So I have this image: Cross

It looks like a small image, but actually it comes from a camera with a large resolution, which means the matrix of this image will be of large dimensions. What I need to do is to find the cross in the fastest way possible.
I tried to scan all of the matrix and find where the white lines are but I'd like to hear from you maybe you have better and faster solutions for this problem.
Keep in mind that this image comes from a camera so this may look like a regular case but in reality a lot of stuff can happen, like cross not in the center, cross moves etc.
Thank you very much and have a good day.

--Edition--
I am sorry for not answering the questions. I am a student and unfortunately my schedule is crazy.. I will try my best to be online.
The answers to your questions are:
What is the full size of the original image? Maximum image size is: Width: 1936 px, Height: 1216 px. However, since we design the program for users, the user can manage the resolution as he/she pleases.
What OS are you using? Windows 7/8/10
What language/toolset? I am writing in C#. I was given an API of a camera and I need to use this API in order to make calculations regarding the image I get from the camera.
Have you got a GPU? I think so..
Multi-core CPU? Umm.. I don't think so..
How do the last two questions relate to my question? I am asking because I am new to this..




Another questions asked:
+ Since the position of the cross is user defined, it can be wherever on the screen. It can also not show up at all, since the user can forget to open up the camera or whatever.. So basically, anything can happen.
In addition, the camera itself maybe broken or not perfect and some unexpected things may appear on the screen like random white pixels or stuff like that.
+ About the minimum width of the cross lines - I actually don't know.. It comes from a camera so it's basically light. I depends on the users and what device they are using. So I guess the minimum is 1 px in that case.
What I mean by "finding the cross" is: I need to find the center of the cross in the image in the fastest way possible, just like a measuring device.

Right now the algorithm is scanning the matrix of the pixels given by the picture on the screen and finding the maximum value in the row, per each row.
Then, calculating where it is and doing some math with it..
But the point itself is to get the position of the center of the cross in the fastest way possible while keeping the accuracy of the calculation. We don't want to lose data since the program can be used in a very sensitive environment..
I hope I made things clearer..



Again, sorry for the delay and thank you for your help.

  • What is the full size of the original image? What OS are you using? What language/toolset? Have you got a GPU? Multi-core CPU? – Mark Setchell Dec 01 '16 at 11:19
  • 1
    Some more detail about the image you expect to receive certainly wouldn't hurt. For instance, actual resolution, even if approximate. Whether or not you can expect the cross to reach the image edges as this one does in 3 places, how many pixels as a minimum the lines of the cross will be in width, what exactly you mean by 'finding the cross' - Do you seek to find the intersection of the lines? Do you seek to find a bounding box for a cross that doesn't touch the image borders? etc, etc. In a task that requires finding the answer as quickly as possible, these are all fairly important. – enhzflep Dec 01 '16 at 11:54
  • How about answering some of the questions that have come up since you asked 5 days ago so that folks can assist you better? Click `edit` under your original question and add extra details/explanations if you don't have enough reputation points to add comments. – Mark Setchell Dec 06 '16 at 19:48

3 Answers3

1

All depends on real image quality. For given example it is enough to find the brightest pixel in every line and column and build least-squares approximations for lines, or calculate image moments

If there are arbitrary objects and some noise presents, one could try Hough transform to determine lines

MBo
  • 77,366
  • 5
  • 53
  • 86
0

Image processing is expensive computationally. Focusing on quality, based on the example you gave, the first thing you should consider is applying a high-pass filtering over the image. It will make it easier to find the cross and harder to fall on a wrong detection. If you're looking for a good reference there is a book called "Digital Image Processing" from Rafael Gonzalez that cover basically everything you will need to know.

rafrcruz
  • 117
  • 7
0

Updated Answer

The question about your CPU being multi-core (and having a GPU) is critical - it's not good enough not to know.

  • If your camera takes 50ms to acquire an image and you do no processing, you can do 20 frames a second.

  • If you spend 50ms acquiring a frame and then 50ms processing it, you can now only do 10 frames a second.

  • However, if you have a multi-core CPU and write multi-threaded code, you can acquire a frame in 50ms and have, say each of 3 other threads/cores doing 50ms of processing before the next frame comes, so suddenly you can do 150ms of extra processing per frame and still keep up the frame rate you achieved with no processing at all.

The above also applies to your GPU.

Have a look at the red/green graph at the bottom of my other answer here to better understand what I am saying about threads.

Also, the type of operations summing up across frames lends itself very much to SIMD optimisations, so you need to make sure your compiler is set to optimise/vectorize sequential memory accesses - or hand-code SIMD versions.

Original Answer

You could try resizing/summing across the image to a tall column, 1 pixel wide. And then likewise down the image to a long bar 1 pixel high. Then look for a maximum (or centre) of the corresponding white bars:

enter image description here

I have shown the bars 10 pixels wide here so you can see them.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • An interesting shortcut, but...throw some noise on that background and see how it reacts - given that the lines are thin, one won't need much noise to overpower the lines signal. Also unusable for a diagonally oriented cross.(I'm afraid one won't get a proper solution ignoring that there are **lines** to be detected and those lines better be orthogonal to form a cross) – Adrian Colomitchi Dec 01 '16 at 12:03
  • @AdrianColomitchi Yes, I concede absolutely that diagonal lines will cause problems - I guess OP will have to say if that is likely to be an issue. Likewise with noise though that could be filtered. I just like the idea as it is computationally inexpensive and may be useful as a first estimate of where to look even if not a perfect solution for all input images. – Mark Setchell Dec 01 '16 at 12:09
  • Mmm... given how thin are those lines, I'm afraid any off-the-self denoising will nuke those lines without right to an appeal. In regards with dealing with the diagonals, given how inexpensive the algo is, I wonder if sum-projecting not only on the sides but taking another shot on some other directions wouldn't actually be beneficial (after all, one only needs to compute some sin/cos pairs once and project on the other directions in the same image-scan cycle) – Adrian Colomitchi Dec 01 '16 at 12:25
  • @AdrianColomitchi I'm with you all the way:-) – Mark Setchell Dec 01 '16 at 12:33
  • Wow, it is very creative. I hope this solution can handle real-life extreme situations.. I will suggest it, thank you. – kidneyThief Dec 08 '16 at 13:01
  • So I suggested it and my next question is: is there an algorithm that resized and minimizes the picture without scanning the whole thing because right now the algorithm we work with does pretty much this scanning and it slows down the system. – kidneyThief Dec 08 '16 at 13:16