I’ve got a scenario that you can envision this way:
Start off with an image that is 100 pixels wide by 1000 pixels tall.
In addition to that image, you have a set of cropped sections of that image. Each section is 100 pixels wide by 100 pixels tall. The part of the image contained in the section varies. For example, you might have one that starts at the very top (pixel 0), then one at vertical pixel 3, then one at vertical pixel 9 and so on.
What I need to do is find a way to look at those set of smaller pictures and pick out the smallest number of sections that would give me the most coverage of the original image.
A couple of notes:
- The content of the image doesn’t really matter. It’s really matching up the coordinates that matters.
- There will never be gaps in the image when reconstructed, but there may not be enough pieces to reach the bottom.
- There will be a lot of overlap among the sections. In fact, there will be cases where there will be only a pixel or two of (vertical) difference between two sections.
Can anyone point me in the right direction here? I can do this sort of brute force… but I assume there’s a better way.
I’m sorry, but I fail to see why this problem is NP-hard.
The general idea is that you’ll remove iteratively bottom parts of your image by selecting the “best” section, that is
Begin by sorting the sections. You’ll get something like (0,1,3,10,…,988,999) where 0 corresponds to a section that begins at the top pixel. (And the one corresponding to 999 covers only one line)
Suppose your original image is 100xN. Initially, N=1000.
Let n be the index of the image that best covers the end of the original image : i.e n is the smallest number in that list such that n+100>=N. If there is no such number, n is simply the biggest number.
If your sorted list is (0,1,…899, 900, 901,..,999) then n=900
If your sorted list is (0,1,…899, 905, 910,..,999) then n=905
If your sorted list is (0,1,…,888,898,) then n=898
Then start again with N=n (you’ve removed a part of the bottom of the original image) (of course, remove from the sorted list all the sections that are “>=n”)
I think that setting fixed-height sections (100 pixels) removes the NP-hardness.