Hi Larry, I could use the ImageBuf.write that outputs to an already open ImageOutput on the Python side. Is there a reason that is currently missing or is that something that's easy to add?
- Frank ________________________________ From: Oiio-dev <[email protected]> on behalf of Larry Gritz <[email protected]> Sent: Sunday, July 12, 2020 8:01 PM To: OpenImageIO developers <[email protected]> Subject: Re: [Oiio-dev] Cropping of multi Images Hi, sorry this seemed to slip through the cracks. I hope the information is still useful to somebody. You have the basic idea for how to write a multi-subimage file using the ImageOutput interface, with the data just in a big array. If I understand your question correctly, you want to use ImageBufAlgo:: crop() to crop those images to a given ROI, but now you are stuck for how to write a multi-image file (multi-part exr) for the resulting ImageBuf's. Here's the outline of how you would do that: // Start off the same way: you have your original images all in the big 'scratch' buffer, // and an array of specs. // Assume you want to crop them all to ROI 'cropped_roi'. // Make a new set of specs with the cropped sizes std::vector<ImageSpec> cropped_specs (orig_fb_count); for (int s = 0; s < orig_fb_count; ++s) { cropped_specs[s] = specs[s]; cropped_specs[s].set_roi (cropped_roi); } // Open an ImageOutput for multi-subimage as you did before out->open (filename.toStdString(), orig_fb_count, cropped_specs.data()); // Crop each individual image and write it unsigned int xoffset = 0; for (int s = 0; s < orig_fb_count; s++) { if (s > 0) { // Not needed for the first, which is already open out->open (filename.toStdString(), cropped_specs[s], ImageOutput::AppendSubimage); } // Make a light-weight ImageBuf that "wraps" your existing data. ImageBuf uncropped (specs[s], scratch + xoffset); // Crop it. (This will make a copy of just the cropped region. ImageBuf cropped = ImageBufAlgo::crop (uncropped, cropped_roi); // Write the new ImageBuf to the open file cropped.write (out); // Move to the next buffer position. xoffset += specs[s].image_bytes(); // Note: the 'cropped' ImageBuf will automatically be destroyed and // have its memory freed when it exits scope at the end of this loop. } On Jun 3, 2020, at 6:24 AM, Sven Steinbauer <[email protected]<mailto:[email protected]>> wrote: Hello, I've sent an email about this before but I think my reply got lost somewhere. Anyway, I am trying to crop a multi-image Exr file. I have managed to write out the multi-image like this (because out->supports("appendsubimage") returns false) out->open (filename.toStdString(), orig_fb_count, specs); // Write the individual subimages unsigned int xoffset = 0; for (int s = 0; s < orig_fb_count; s++) { if (s > 0) { // Not needed for the first, which is already open out->open (filename.toStdString(), specs[s], ImageOutput::AppendSubimage); } out->write_image (TypeDesc::BASETYPE(specs[s].format.basetype), scratch + xoffset); xoffset += specs[s].image_bytes(); } Here the scratch is a scratch file buffer storing all the aovs contiguously, and the arrap of specs stores the spec for each one. This is working great, but I want to add an autocrop feature. I can calculate the ROI (or BBox) for the overall image, but I am not sure how to crop the images. The original code I inherited uses ImageBufAlgo::crop, and then ImageBuf::write to save the file. I am not sure how to write out the result from the crop to a multi-image EXR out->open (filename.toStdString(), orig_fb_count, specs); What's the correct method to crop the image and write it out as a multi-image EXR? SVEN STEINBAUER​ Senior R&D Engineer T +44 20 7287 4041 [http://asset.themill.com/emailsig/1560254660/PrideLogo.png]<https://urldefense.com/v3/__http://www.themill.com/__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4TCUXIu7g$> SUPPORTING WORLD PRIDE MONTH 2020 THE MILL 11‑14 WINDMILL STREET, LONDON, W1T 2JG FOLLOW @MILLCHANNEL | FACEBOOK<https://urldefense.com/v3/__http://www.facebook.com/millchannel__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4TVXRP_bw$> | LINKEDIN<https://urldefense.com/v3/__https://www.linkedin.com/company/9328__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4RYGusChg$> | INSTAGRAM<https://urldefense.com/v3/__https://www.instagram.com/millchannel__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4RmqmSbsQ$> | THEMILL.COM<https://urldefense.com/v3/__http://www.themill.com/__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4TCUXIu7g$> _______________________________________________ Oiio-dev mailing list [email protected]<mailto:[email protected]> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org<https://urldefense.com/v3/__http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org__;!!Ci6f514n9QsL8ck!0TzpJJ4BCk2WtjXxr9ysE0QK6z_F6_xYxmS1McIgOXROPOIPedwOW4QsQwaFmg$> -- Larry Gritz [email protected]<mailto:[email protected]>
_______________________________________________ Oiio-dev mailing list [email protected] http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
