Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow "extract" outside original image bounds. #19

Merged
merged 2 commits into from
Apr 20, 2015

Conversation

danvk
Copy link
Contributor

@danvk danvk commented Jan 8, 2015

The problem was that y0-pad and x0-pad in psegutils.extract_masked could become negative. Chaos ensued.

This pads the output of extract with white pixels when you try to extract a region that goes outside the original image.

Fixes #18

@tmbdev
Copy link
Collaborator

tmbdev commented Jan 9, 2015

Hi, thanks. That looks like a reasonable fix, but I'm concerned that extract now can return images that are of a different size than what the caller expects. I'm not sure whether that is going to break code somewhere. It's probably better to just return the exact size subimage that was requested but pad it.

Doing that directly is sort of fiddly, but it's actually easy to do with scipy.interpolation.affine_transform; you can give that negative offsets, desired output width and height (output_shape), and boundary conditions; just use an identity matrix for the matrix. order should be 0 or 1. Do you think you could change your patch to use affine_transform instead?

(I'd do it myself, but I'm busy bug fixing the clstm implementation right now.)

@danvk
Copy link
Contributor Author

danvk commented Jan 9, 2015

extract will always return images that are (y1-y0)x(x1-x0), which wasn't the case before.

I can take a crack at using scipy.interpolation.affine_transform.

@danvk
Copy link
Contributor Author

danvk commented Jan 12, 2015

I've reworked the code to use affine_transform and added a test image which reproduces the problem. Let me know if this looks right.

@danvk
Copy link
Contributor Author

danvk commented Jan 19, 2015

ping

@tmbdev
Copy link
Collaborator

tmbdev commented Jan 29, 2015

Thanks; sorry, I was traveling. Thanks for looking into the patch. You still special-case interpolation.shift in that patch. The nice thing about affine_transform is that it doesn't need any special cases for any shifts. If you know what I mean, maybe you could simplify the patch to just use affine_transform for everything (mostly deleting a few lines of code), or I can do it soon.

tmbdev added a commit that referenced this pull request Apr 20, 2015
Allow "extract" outside original image bounds.
@tmbdev tmbdev merged commit 92c8407 into ocropus-archive:master Apr 20, 2015
QuLogic pushed a commit to QuLogic/ocropy that referenced this pull request Sep 29, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError: shape mismatch in ocropus-gpageseg
2 participants