Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about usage and results. #8

Closed
Youjose opened this issue Oct 29, 2022 · 7 comments
Closed

Questions about usage and results. #8

Youjose opened this issue Oct 29, 2022 · 7 comments

Comments

@Youjose
Copy link

Youjose commented Oct 29, 2022

Hello there! Amazing library here on what this can, however I am getting runtime errors on certain images, perhaps due to blank white images as pieces existing in the segments.

I have 120 image pieces of a size, I used the pull request branch to load these in as given by the guide.

#!/usr/bin/env python3

from puzzles.models import PiecesPuzzle
import os

here = os.path.abspath(os.path.dirname(__file__))

images = [os.path.join(here, "img", x) for x in os.listdir(os.path.join(here, "img"))]
puzzle = PiecesPuzzle(images, height=12, width=10, min_piece_size=96) # Here I know for a fact that the original image is 10x12 in pieces.

fig = puzzle.get_puzzle_figure()
fig.savefig(os.path.join(here, "pieces.png"))

puzzle.metrics()

puzzle.solve()
solved_fig = puzzle.get_solved_figure()
solved_fig.savefig("solved.png")

It's also good to note that I don't know what min_piece_size actually us, as the documentation didn't make it clear (I just assumed it's the minimum rect dimension)
Here are is the link to the pieces in question:

Moreover, I think matplotlib loading pure white images and other similar images break them inn output, as seen here by pure purple segments, and also notice the broken segments with yellow outline. I am not sure if this affects how the lib works internally, looking over the code.

however this errors is produced:

C:\Users\Username\AppData\Local\Programs\Python\Python39\lib\site-packages\puzzles-0.0.14-py3.9.egg\puzzles\models.py:152: RuntimeWarning: divide by zero encountered in log
  return np.log(la.norm(np.minimum(edge_diff, self.max_rgb - edge_diff), ord=1))
C:\Users\Username\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\_methods.py:179: RuntimeWarning: invalid value encountered in reduce
  ret = umr_sum(arr, axis, dtype, out, keepdims, where=where)

and also the output image is not what I expect, as we know for sure that the output image should be 10x12 pieces. But this is perhaps the result of the errors above.

@vsoch
Copy link
Owner

vsoch commented Oct 29, 2022

Can you please post the image directly here (if the link goes away, etc?) I suspect you are choosing a piece size that isn't working with the dimension, and I agree we need better docs for that! I'm going out for a bit but I can take a look and test with the image later. Thanks for posting the issue!

@Youjose
Copy link
Author

Youjose commented Oct 29, 2022

Thanks for replying! And after some thought I think this is rather my problem, as the image seems (probably) impossible to be reshuffled due to excess of white edges and so on, noticed this after I read your pull requests comment.

This is a quick 30 minutes of programming to add support for creating (and solving) a puzzle from already generated square pieces! Since the algorithm is based on edge matching, this will not work for images with constant/uniform color at most edges, or those that don't fit nicely into squares/rectangles of equal size.

which basically describes our image in question.

@vsoch
Copy link
Owner

vsoch commented Oct 30, 2022

Thank you! And indeed we should handle the white edges (and not divide by 0 but a very small number). Thanks for sharing the images we will have a look tonight! Ping @tabakg

@vsoch
Copy link
Owner

vsoch commented Oct 30, 2022

okay please see https://github.com/vsoch/puzzles/pull/101! We will need more work to handle dimensions, but this is a start. Thanks for opening the issue - we had only developed this for simple images (without a lot of white) and will try to improve it. If you want to contribute please also feel free to go ahead!

@tabakg
Copy link

tabakg commented Oct 31, 2022

Hi @LittleChungi ! We've adopted the edge matching algorithm so there is improved performance for your image! Please see #11. Note that we still recommend that you use images without significant white borders. Please see the branch and let us know if you see an improvement. Minimally, the bug should be fixed. Thanks!

@Youjose
Copy link
Author

Youjose commented Nov 1, 2022

Thank you as well as @vsoch ! I've seen the new updates and both look promising! I apologize for the extremely late reply, but I will check those and go over the code as well, and reply back to you as soon as possible!

@Youjose
Copy link
Author

Youjose commented Nov 9, 2022

Works very well! I improved the script for my use case since I know the exact x and y lines per block, calculate the border cost and sort that way, it gets results fairly well, although sometimes it gets image rotation wrong, which is expected, could be fixed with manual tweaking.

There's a lot of hardcoding in my script, was wishing to contribute on this project, but its not feasible, since it's specifically tuned for my use case at this point.
Thanks for the help tabakg and vsoch!

@Youjose Youjose closed this as completed Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants