ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
462 stars 65 forks source link

newbie question #343

Closed MathiasBeller closed 2 years ago

MathiasBeller commented 2 years ago

Hi! I have 16-bit Tiff microscopy images, which I would like to analyze with the magick package. Loading of the file(s) works. I will need to get access to the greyscale brightness values (e.g. brightest pixel in image) as well as should like to break up the image into regular blocks (e.g. the original image is 1000 by 1000 pixels and I would like to get regular block of 100 pixels width and heigth) to calculate the averaged signal in this image area and represent this then by a heatmap or similar. My main problem is the object structure of the class "magick-image". I would be grateful if you could point me to how to convert the image data to a matrix or data frame for further analysis. Thank you very much in advance for your help! Best, Mathias

dcaud commented 2 years ago

Maybe something like:

image_data(rose) # rose is an object provided in the magick package

from ?image_data()

The img[[i]] method is an alias for image_data() which extracts a single frame as a raw bitmap matrix with pixel values.

Then you could do something the package maintainer wrote here: https://jeroen.github.io/munster2018/#25

Using image_crop() you could break up the image.

MathiasBeller commented 2 years ago

Thank you! In the end I switched to Python and used opencv and Scikit-image. I will look though also at your solution.