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

Cropping using Images #130

Closed
natema opened this issue Jun 8, 2020 · 7 comments · Fixed by #167
Closed

Cropping using Images #130

natema opened this issue Jun 8, 2020 · 7 comments · Fixed by #167

Comments

@natema
Copy link

natema commented Jun 8, 2020

After searching how to crop an image in the docs, I realized that PaddedView can be used to do that.
Perhaps it would be useful to mention in its docstring that PaddedView also works if the output image size is smaller than the input one, effectively implementing a cropping functionality, so that the function would show up when searching for related keywords.

@johnnychen94
Copy link
Member

johnnychen94 commented Jun 9, 2020

I'm not sure if I get your idea correctly, could you provide a demo for that? If available, a demo card could also be helpful for others.

@timholy
Copy link
Member

timholy commented Jun 9, 2020

The easiest way to crop is indexing: img[102:418, 208:511].

@natema
Copy link
Author

natema commented Jun 9, 2020

@johnnychen94 sorry, I agree that my paragraph above is indeed a bit confusing.
Some details about my specific use case could be helpful.
I have to pad and crop images of various sizes so that they're all $n\times n$; some image size are greater, some smaller than $n$.
I was then going to first crop the extra entries by indexing, as @timholy suggested, and then pad with PaddedView. I then realized that a single call to PaddedView would do the job, since it can be used to anti-pad (crop) safely (i.e. without the assumption that the output range is a subset of the input entries).
So, I just wish that had found some hints for the latter trick in the docs.
I can propose some lines to add to the docs for it, if you agree, but if you think it is not noteworthy enough, we can close this.

@timholy
Copy link
Member

timholy commented Jun 9, 2020

No, seems worth documenting. Any changes you want to propose to improve the documentation would be welcome. As @johnnychen94 suggests, a demo card would be particularly awesome, but really anything would help.

@johnnychen94
Copy link
Member

johnnychen94 commented Jun 10, 2020

I then realized that a single call to PaddedView would do the job

Although the trick seems trivial (PaddedView restricts/expand its indices if it is explicitly provided), that is something I didn't come up with and I think it worth a demo or paragraph here. I myself might try as you did, too.

Probably it's also worth supporting usage like: X_p = paddedviews(-1, Xs...; indices=(0:5, 0:5))?

@ashwani-rathee
Copy link
Member

I wish to take this up,I am almost done with demo for resize,scaling..should I include cropping in that one only or separately??

@johnnychen94
Copy link
Member

johnnychen94 commented Nov 23, 2020

Good to know that you're interested.

I assume none of them are sufficiently long? These seem to be spatial transformations so might be good to be one demo. You could also find some ideas from https://evizero.github.io/Augmentor.jl/stable/democards/operations/ I never try them with Images core functionality, so it might be worth exploring.

FYI, I've also introduced PaddedViews in https://juliaimages.org/stable/democards/examples/spatial_transformation/alpha_compositing/#Alpha-Compositing

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

Successfully merging a pull request may close this issue.

4 participants