there is an array i on j, each element of the array stores the color of the pixel of the picture. The picture itself is a preview of other pictures, separated by a white stripe, and the thumbnails themselves can also contain some sequences of white pixels example

the task is to find the centers of these thumbnails, who will tell you how to solve it?

  • And what is the center in your understanding? It is important. - VladD
  • And I would divide the task into two: cut the big picture into small ones, and find the center of each separate little picture. - VladD
  • By the way, where does the big picture come from? Why isn't she cut into pieces in advance? If this is a preview of your pictures, just do not stick everything together in one pile, it will be easier for you. - VladD
  • under the center here I mean the width and height of the preview divided by 2 - user193361
  • Aha, then the second task is self-evident, and the question is in the first. - VladD

1 answer 1

Okay, why isn’t the naive algorithm appropriate?

You go in a cycle of X. For each X, check whether the entire column with the given X consists of white cells (let's call it “white column” for brevity). Minus the first column can be considered white for the simplicity of the algorithm. If this column is white and the previous one is not, then this X is the end of the picture, remember it. If this column is not white, and the previous one was white, this is the beginning of a new picture, remember it.

Same for the Y coordinate.

Having the beginning and end of the picture in X and Y, calculate the arithmetic averages.

  • and such an idea occurred to me, but it was embarrassing that some previews could be white, “scoot” on one of the axes, and it could happen that the whole row / column could be white - user193361
  • @ user193361: It can happen, of course. If you have, for example, all three medium previews in the same place have a white band, then you can’t distinguish them at all. Unless you know also the minimum width of a white strip. - VladD