Open foreignsand opened 10 months ago
I am also running into a similar issue when trying to convert a raster to an "im" object in R 4.3.2 and spatstat 3.0-7. I'm trying to use a raster as the mu variable in rMatClust and previously the code below worked (R version 4.2.2, spatstat 3.0-2) but now I'm getting an error that X can't be converted to a pixel image. I assume this is because the previous version of "as.im" relied on maptools which is no longer available.
rMatClust(10, 10, mu = as.im(myraster)
I have found a workaround to convert the raster to a matrix, then invert and transpose it so it is correctly aligned, and then use spatstat.geom::as.im() to convert it, and I use the calls "xcol" and "yrow" in as.im() to define the extent of the window. However, this modified code produces no point outputs when using the same parameters as the original method.
I've reverted to an old version of R to get my code to run. Is there any workaround to convert raster or terra objects to pixel images?
Thank you Julia S
I am attempting to import a bitmap image into R, rasterize it, and calculate the area of discrete regions in the image using spatstats. Importing the bitmap into R and converting it to a raster isn't a problem:
20231031_110019.bmp.zip
From what I've found googling, if I can convert the raster to an owin object or ppp (hypothetical name ppp_01), I can then calculate the area of the discrete ovoid regions in the object using the following code:
So I have at least two possibilities:
If you can help me figure out how to get my desired result, I would be SO grateful!
Many thanks, foreignsand