简体   繁体   中英

Analyse Pixel distribution of a Rasterlayer

I really really need some advice. I have a Raster with many pixels. Each pixel has one value. Now I want to do a spatial analysis of these pixels. I want to see in which region have the most pixels and were not. Sounds simple, but it's not.

I had an idea to do this with the kernal density but it does not work with rasterlayer. It doesn't work either with ppp, because you can't transform a raster into this data type. I'm really lost. I don't know what could work. So I would be very grateful if I could get some help.

My Pixels looks like this:
像素

There must be a way to show the regions with the most pixels and so on. But I don't know how I can do that.

Short answer : convert your raster object to a pixel image of class im in the spatstat package. Then use Smooth.im . Example:

library(spatstat)
Z <- as.im(my_raster_data)
S <- Smooth(Z)
plot(S)

Long answer : you're using the term "pixel" in a nonstandard sense. The pixels are the small squares which make up the image. Your illustration shows a pixel image in which the majority of the pixels have the value 0 (represented by white colour), but a substantial number of individual pixels have values greater than 0 (ranging from 0 to 0.3).

If I understand correctly, you would like to generate a colour image or heat map which has a brighter/warmer colour in those places where more of the pixels have positive values.

The simplest way is to use Gaussian smoothing of the pixel values in the image. This will calculate a spatially-varying average of the values of the nearby pixels, including the zero pixels. To do this, convert the raster to a pixel image of class im in the spatstat package

Z <- as.im(my_raster_object)

then apply Smooth.im

S <- Smooth(Z)
plot(S)

Look at the help for Smooth.im for options to control the degree of smoothing.

If you wanted to ignore the actual colours (pixel values) in the input data, you could just transform them to binary values before smoothing:

B <- (Z > 0)
SB <- Smooth(B)
plot(SB)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM