1

Good evening :)

I would like to create a script capable of cutting the images present on large image one by one, so I want to cut out the 9 different images.

enter image description here

It is not so difficult to cut out these images because in fact it is enough just to cut out the good lines and the turn is played .. So where is my problem?

This problem becomes complicated, because there exist indeed several variants of great images; For example, it is likely that my script falls on a large image such as enter image description here

(Here, you can see 8 different images, so the lines to be cut are different).

So how do I get there?

I am still a beginner and I do not understand everything :(

I hope I have been as clear as possible. Thank you very much in advance!

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86
Marshall Cocop
  • 151
  • 3
  • 16
  • Please add the pictures to the question body and not a link to the pictures. Are the number of different pics known and their size ? – Tony Tannous Jul 26 '17 at 21:54
  • I can not insert the body of the image for the moment (Because my reputation on the forum is not a 10). In short :) The dimensions are of 100x100 for the images of the first link, and of 152x87 for the second – Marshall Cocop Jul 26 '17 at 22:05
  • Sorry wasn't aware of that. I did it for you. Also please share what you've tried so far (your script). – Tony Tannous Jul 26 '17 at 22:09
  • No problem ! It's very nice of you thanks :) – Marshall Cocop Jul 26 '17 at 22:10
  • Can you add anything that would help? Can the cuts be rotated at an angle sometimes? Can there be gaps between the images? Will the cuts always go across the full width of the image, or will they sometimes stop in the middle and have to go vertically one way before proceeding horizontally? Will all the images within one picture all be the same size as each other? Is there a max or min number of images across? Or vertically? What OS do you use? Are the images all PNG? JPEG? – Mark Setchell Jul 26 '17 at 22:27
  • Is there any additional information where the cut points/lines might be ? Or the images are the only input ? – sbond Jul 26 '17 at 22:28

1 Answers1

1

Create two arrays, one in the length of the image width and one in the length of the image height and init them with zeroes.

Since you are trying to test similarity of horizontal lines and vertical lines, you should iterate through the image pixels and compare each pixel in the position (x,y) to the pixel in the location (x+1,y) and (x,y+1) meaning each pixel is compared to the pixel right to it and the pixel below it. The result of each comparison should result with a similarity percentage.

To calculate similarity percentage of two pixels you can follow the answer to this question: Algorithm to check similarity of colors

The percentage result of each horizontal comparison of pixels in the location (x,y) should be added to the value in the horizontal array in the location x. So for example if:

pixel(3,0) compare to pixel(4,0) = 80%
horizontalArray[3] += 80% (80)
pixel(3,1) compare to pixel(4,1) = 72%
horizontalArray[3] += 72% (152)
pixel(3,2) compare to pixel(4,2) = 95%
horizontalArray[3] += 95% (247)
...

And in a similar way calculate the values for the vertical comparison:

pixel(0,3) compare to pixel(0,4) = 22%
verticalArray[3] += 80% (22)
pixel(1,3) compare to pixel(1.4) = 10%
verticalArray[3] += 72% (32)
pixel(2,3) compare to pixel(2,4) = 76%
verticalArray[3] += 95% (108)
...

After iterating through all pf the image pixels divide the values in the horizontalArray with the image height and the values in the verticalArray with the image width. the result of this action leave you now with two arrays containing average similarity percentage of each horizontal and each vertical line in you picture, now you can choose a arbitrary a magic number, lets say 15% and say that each line that got less than 15% similarity is a line you will perform a cut by it.

Test the script and see how accurately it find the correct lines.

If it's not sensitive enough increase the the value of your "magic number", if it is too sensitive and find lines where it shouldn't decrease the value of this magic number and try again.

EDIT

I edited my suggestion to color similarity formula as it had mistakes in it that would lead to not accurate results. Instead I added reference to another answer dealing with the question of color comparison, use it with the rest of the algorithm and it should work.

Ori Shalom
  • 470
  • 4
  • 11
  • Thank you very much for this valuable information ... I did not know how to do it, so thank you again! I will try to realize this, I keep you informed :) – Marshall Cocop Jul 26 '17 at 22:49
  • Notice, my update, I had a mistake in the color similarity formula, instead use the answer in here for this part: https://stackoverflow.com/questions/5392061/algorithm-to-check-similarity-of-colors – Ori Shalom Jul 27 '17 at 10:58
  • I understand more the calculation that you indicated to me in the previous message: ') Indeed, I could understand how to recover these RGB values, but how to achieve it for YUV values: / Some research is necessary, I come back to you when I would have found solutions :) – Marshall Cocop Jul 27 '17 at 12:11