Can't interpret X as a point pattern, ask for help!
library(imager) library(spatstat)
Read image
img <- load.image("C:/Users/yyan2/Documents/Dec 21/F10F.jpg") img_gray <- grayscale(img) threshold <- 0.5 # adjust this value as needed img_thresh <- img_gray > threshold class(img_thresh) # convert the binary image to a matrix [1] "pixset" "imager_array" "logical"
binary_image <- as.im(matrix(as.numeric(img_thresh), nrow = nrow(img_thresh),
-
ncol = ncol(img_thresh))) # convert to binary image
image_window <- owin(c(1, ncol(img_thresh)), c(1, nrow(img_thresh))) point_pattern <- as.ppp(binary_image, window = image_window) Error in as.ppp.default(binary_image, window = image_window) : Can't interpret X as a point pattern
I have tried all kinds of function that I know, it won't work. so frustrating