Thank you so much for the “recipe” Larry - your first approach works an absolute treat!
Regards, Simon. > On 28 Sep 2020, at 17:38, Larry Gritz <[email protected]> wrote: > > Oh, interesting problem! > > The resize() description says: > > /// Set `dst`, over the region of interest, to be a resized version of the > /// corresponding portion of `src` (mapping such that the "full" image > /// window of each correspond to each other, regardless of resolution). > /// If `dst` is not yet initialized, it will be sized according to `roi`. > > bool OIIO_API resize (ImageBuf &dst, const ImageBuf &src, > string_view filtername = "", float filterwidth=0.0f, > ROI roi={}, int nthreads=0); > > > It certainly doesn't make it easy to do what you want -- I think this points > out the need to have a variety of this call that takes a srcroi and a dstroi > and resizes between them, instead of the rescaling factor assuming that the > two images correspond to each other according to their "full" windows (in > OIIO lingo; this is what OpenEXR calls the "display window"). > > But maybe we can work around this creatively. > > The first approach I can think of might work like this: > > 1. Save the full widows of both images with ImageBuf::roi_full(). > 2. Reset their full windows (using ImageBuf::set_roi_full()) of the src to > its data window (ImageBuf::roi()), and the dst to the subregion roi where you > want it to end up. This is not expensive, it's just metadata, doesn't copy > any pixels. > 3. Now do the resize: ImageBufAlgo::resize(dst, src, filtername, > filterwidth, subset_roi); Only the dst pixels in subset_roi will be altered, > but because we carefully set the full window sizes, it ought to get a correct > copy of the whole src image. > 4. Now restore the full windows to their original values (saved in step 1). > > There should definitely be a way to do this all in one step, sorry that there > is not. > > Another way to do this might be to use ImageBufAlgo::warp(), which works the > same way as resize -- it assumes that the "full" windows of the two images > correspond to each other. But you give it a 3x3 matrix (a 2D homogeneous > transformation), and with that you could arbitrarily map which area of src > corresponds to that subregion of dst that you are writing to. You'd probably > need to sit down with pencil and paper to figure out how to construct just > the right matrix, but it should work. > > >> On Sep 28, 2020, at 7:00 AM, Simon Smith <[email protected]> wrote: >> >> Hi, >> >> I’m trying to work out if/how I can resize one ImageBuf into a sub-region of >> another without any intermediate ImageBuf's to hold the resize. >> Essentially I want to take an image and create a new one of the same pixel >> size, but with a border around it. >> >> I’m doing this in memory with C++. >> Does anyone have any ideas on how this could be done without the need for >> extra memory/copy? >> I can’t immediately see anything in the API - they all seem to require a >> smaller dst ImageBuf for the result of the resize - but I’m sure there must >> be one in there somewhere! >> >> >> Best Regards, >> Simon >> >> --- >> Simon C Smith >> Co-Founder & CTO >> www.lightmap.co.uk >> >> Email confidentiality notice: >> This message is private and confidential. If you have received this message >> in error, please notify us and remove it from your system. >> >> _______________________________________________ >> Oiio-dev mailing list >> [email protected] >> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org > > -- > Larry Gritz > [email protected] > > > > > _______________________________________________ > Oiio-dev mailing list > [email protected] > http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
_______________________________________________ Oiio-dev mailing list [email protected] http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
