asgr / imager

R package for image processing
GNU Lesser General Public License v3.0
17 stars 4 forks source link

Suggestion: Loading subset of image as defined by coordinate set only #15

Open Gewerd-Strauss opened 7 months ago

Gewerd-Strauss commented 7 months ago

Hello,

this is kind of related to #14, but only tangentially so.

Image-loading takes quite a bit of time if you are processing 4k x 6k sized images.

In fact it takes so prohibitively long that I am currently trying to figure out how to load subset of an image only. Imager does not allow for this; but RBioFormats does. However, setting up that package properly has turned out to be very complicated.

A good amount of the image is unlikely to be relevant for me, and I'd rather just not load it to begin with and save myself a lot of time and resources.

Could imager::load.image() be expanded by 4 parameters x1,x2,y1,y2 defining the range of pixel locations imported?

As a reference, the RBioFormats has a suitable function that does this in principal.

RBioFormats::read.image(
                                file = image.path,
                                ...,
                                subset = list(x=x1:x2,y1:y2)
                            )

Unfortunately, I have found that its image-data is not 1-to-1 with the data loaded by imager. I would not have assumed those to load identical data, but I certainly hoped for it. At this point I am not sure if the value differences are small enough so that I can deprecate imager::load.image() for RBioFormats::read.image() to implement this; because I have not come around to testing this particular change.

Nonetheless I would prefer a native support in imager so that I don't have to worry about these value diffs. Additionally, setting up RBioFormats() is somewhat of a pain to manage; particularly when you must consider it in the scope of a package, instead of a "normal" script-environment.

Is something like this possible in principal?

Thank you. Sincerely, ~Gw

asgr commented 7 months ago

It’s not something we would plan to work on. Most pre-existing functions are being supported in maintenance mode only. We would aim to fix bugs, but not add features. You are welcome to investigate this functionality on CImg itself and submit a pull request though.

Note there are many packages that can also read in images, and it is relatively painless to convert different formats to CImg.