0

I am now using C++ to study related operations on pathological images, which involves the openslide library. I try to use the openslide_read_region(openslide_t* osr, uint32_t* dest, int64_t x, int64_t y, int32_t level, int64_t w, int64_t h); function to get a part of the image, but I can't understand the usage of dest, how can I use this function to get a part of the image? Or is it possible to convert objects of type openslide_t* into objects that can be manipulated by opencv? Sincere thanks to everyone who helped me

Xifeng
  • 1
  • 1
  • 1
    FYI: [doc. of openslide_read_region()](https://openslide.org/api/openslide_8h.html#a0eeecec682efdf2ef18c8426109acad0). `dest` is a pointer where you have to provide a sufficiently sized buffer. The function will copy the region into this buffer. The doc. states that it has to be _(w * h * 4) bytes in length_. Considering that the pointer type `uint32` provides 4 bytes, `new uint32_t[w * h]` should be correct. (Or, even better: `std::vector dest(w * h); openslide_read_region(osr, &dest[0], x, y, level, w, h);`) – Scheff's Cat Mar 05 '22 at 08:00
  • @Scheff'sCat I'm not sure it's a good idea putting the data into an *h x w* array of 4-byte elements because **OpenCV** will expect an *h x w x 4* array of 8-bit unsigned integers for ARGB data. – Mark Setchell Mar 05 '22 at 09:07
  • @MarkSetchell As `openslide_read_region()` expects a `uint32_t*` you have the choice between Skylla and Charybdis. A clean solution probably would be to make a `memcpy()`. I believe I (in this situation) would allocate an array of `uint32_t` and cast it's data pointer to `uint8_t*` before passing it to OpenCV. (A check of the endianess for the resp. platform couldn't hurt.) – Scheff's Cat Mar 05 '22 at 12:48

0 Answers0