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

Building a multi-channel image from multiple files - what's the right way for sharp? #502

Closed
mhirsch opened this issue Jul 8, 2016 · 4 comments
Labels

Comments

@mhirsch
Copy link
Contributor

mhirsch commented Jul 8, 2016

I'd like to be able to join a collection of images into a single RGB image with sharp, as in vips bandjoin. I can think of two ways to go about this, but I think both of them are a little ugly.

  1. Overload the sharp constructor to accept an object or array containing image filenames or buffers to be joined before being processed:
sharp([image1, image2, image3]).xyz().toBuffer(...);
  1. Add a new function to sharp to join on more image bands / channels after the image has been loaded:
sharp(image1).joinChannel([image2, image3]).xyz().toBuffer(...);

The downside to method 1 is that it is not semantically clear what will happen with the array of images. This could be mitigated by putting them in an object with some descriptive key, such as {0:image1, 1:image2, 2:image3}. The downside to method 2 is that it spreads out the image bands where they should be logically grouped together. There's nothing special about image1 vs image2 and image3, except that it's supposed to end up in band 0.

Thoughts and suggestions? I plan to submit a pr for something like this, and I'm leaning towards method 1.

@lovell
Copy link
Owner

lovell commented Jul 8, 2016

Hi Matt, method 2 is much closer to the underlying libvips operations required to achieve a "bandjoin" and, as you suggest, the method 1 approach to listing multiple input files could lead to ambiguity, so my vote is with the second approach.

joinChannel seems like a good (consistent, clear) name for this operation.

Thanks again for all your recent work to expose more libvips operations. These are much appreciated and have the potential to draw in a whole new community of people more deeply involved with image processing!

@lovell lovell added the question label Jul 8, 2016
@mhirsch
Copy link
Contributor Author

mhirsch commented Jul 8, 2016

Thanks a bunch for your comments. I'll work on something that looks like joinChannel above.

And thanks also for considering my patches. I would love to see something (perhaps a different project) down the road that's closer to a more general node-vips interface but for now, with what I've added, sharp is working really well for me. This is a very high quality project! I really appreciate what you've done with it.

@mhirsch mhirsch closed this as completed Jul 8, 2016
@lovell
Copy link
Owner

lovell commented Jul 8, 2016

"closer to a more general node-vips interface"

Please see #241

@mhirsch
Copy link
Contributor Author

mhirsch commented Jul 8, 2016

Something like that would be fantastic. Is there progress being made in that direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants