How to get the size of a pixel cluster in R


Laurent

I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute?

enter image description here

Alan Cameron

For this kind of image analysis, you can check out EBImage:

install.packages("BiocManager")
BiocManager::install("EBImage")

Your workflow might look like this. First, load the package and read in the image. We'll also show it to show we're on the right track:

library(EBImage)
library(ggplot2)

dots <- readImage("https://i.stack.imgur.com/3RU7u.png")
display(dots, method = "raster")

enter image description here

Now we can use the computeFeaturesfunctions to get the centroid and maximum diameter of each cluster:

dots_bw <- getFrame(dots, 1)
labelled_dots <- bwlabel(dots_bw)
df <- as.data.frame(cbind(computeFeatures.moment(labelled_dots)[, 1:2],
                          computeFeatures.shape(labelled_dots)[, 5:6]))
df
#>        m.cx      m.cy s.radius.min s.radius.max
#> 1  65.73316  25.69588    11.095535     40.69698
#> 2 156.24181 129.77241    19.377341     33.83485
#> 3 483.60853 155.23006     9.419478     16.28808
#> 4 277.21467 409.62152    20.411710     28.77508
#> 5 397.36817 607.47749     8.424518     18.53617
#> 6 224.93790 623.28266     8.530353     15.26678

Now, we want to find out which dimension matches which blob, so let's draw a raster in ggplot and write the maximum pixel dimension above each blob.

img_df <- reshape2::melt(as.matrix(as.raster(as.array(dots))))

ggplot(img_df, aes(Var1, Var2, fill = value)) + 
  geom_raster() +
  scale_fill_identity() +
  scale_y_reverse() +
  geom_text(inherit.aes = FALSE, data = df, color = "white",
            aes(x = m.cx, y = m.cy, label = round(s.radius.max, 1))) +
  coord_equal()

enter image description here

If you want the total number of pixels instead of the maximum diameter (in pixels), you can also start withcomputeFeatures

Related


How to get the size of a pixel cluster in R

Laurent I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute? Alan Cameron For this kind of image analysis, you can c

How to get the size of a pixel cluster in R

Laurent I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute? Alan Cameron For this kind of image analysis, you can c

How to get the size of a pixel cluster in R

Laurent I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute? Alan Cameron For this kind of image analysis, you can c

How to get the size of a pixel cluster in R

Laurent I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute? Alan Cameron For this kind of image analysis, you can c

How to get the size of a pixel cluster in R

Laurent I have a picture in 2 colors. Red pixels are clustered. I would like to know the maximum size of each cluster to compare with an acceptable tolerance. How to do it? Is there a function to execute? Alan Cameron For this kind of image analysis, you can c

How to get pixel values from geoTIFF in R?

NM_ I am trying to get RGB components from a geoTIFF file in R. The colors on the image correspond to the different land classification types, and there is a legend for each classification type in the RGB components. I am using raster library. My code so far i

How to get pixel values from geoTIFF in R?

NM_ I am trying to get RGB components from a geoTIFF file in R. The colors on the image correspond to the different land classification types, and there is a legend for each classification type in the RGB components. I am using raster library. My code so far i

How to get pixel values from geoTIFF in R?

NM_ I am trying to get RGB components from a geoTIFF file in R. The colors on the image correspond to the different land classification types, and there is a legend for each classification type in the RGB components. I am using raster library. My code so far i

How to get pixel values from geoTIFF in R?

NM_ I am trying to get RGB components from a geoTIFF file in R. The colors on the image correspond to the different land classification types, and there is a legend for each classification type in the RGB components. I am using raster library. My code so far i

How to calculate the pixel size of a string?

wolf boy I have rope. I know the font family and the font size it will display. I need to know how many pixels the text will take up in the ui. This way I can determine if other elements are displayed. what should I do? I found several things, but none in the

How to calculate the pixel size of a string?

wolf boy I have rope. I know the font family and the font size it will display. I need to know how many pixels the text will take up in the ui. This way I can determine if other elements are displayed. what should I do? I found several things, but none in the

How to calculate the pixel size of a string?

wolf boy I have rope. I know the font family and the font size it will display. I need to know how many pixels the text will take up in the ui. This way I can determine if other elements are displayed. what should I do? I found several things, but none in the

How to calculate the pixel size of a string?

wolf boy I have rope. I know the font family and the font size it will display. I need to know how many pixels the text will take up in the ui. This way I can determine if other elements are displayed. what do I do? I found several things, but none in the Wind

How to calculate the pixel size of a string?

wolf boy I have rope. I know the font family and the font size it will display. I need to know how many pixels the text will take up in the ui. This way I can determine if other elements are displayed. what should I do? I found several things, but none in the

pheatmaps in R. How to get a cluster

Gabelins I am using Pheatmap with big data. My purpose is to cluster the rows and columns and analyze the main clusters. I upload the datatable and execute the heatmap as follows: library (pheatmap) data<-read.table ("example.txt", header = TRUE) pheatmap(d

pheatmaps in R. How to get a cluster

Gabelins I am using Pheatmap with big data. My purpose is to cluster the rows and columns and analyze the main clusters. I upload the datatable and execute the heatmap as follows: library (pheatmap) data<-read.table ("example.txt", header = TRUE) pheatmap(d

Get cluster size in sklearn in python

username I am using sklearn DBSCAN to cluster data as follows. #Apply DBSCAN (sims == my data as list of lists) db1 = DBSCAN(min_samples=1, metric='precomputed').fit(sims) db1_labels = db1.labels_ db1n_clusters_ = len(set(db1_labels)) - (1 if -1 in db1_labels

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Get cluster size in sklearn in python

username I am using sklearn DBSCAN to cluster data as follows. #Apply DBSCAN (sims == my data as list of lists) db1 = DBSCAN(min_samples=1, metric='precomputed').fit(sims) db1_labels = db1.labels_ db1n_clusters_ = len(set(db1_labels)) - (1 if -1 in db1_labels

Get cluster size in sklearn in python

username I am using sklearn DBSCAN to cluster data as follows. #Apply DBSCAN (sims == my data as list of lists) db1 = DBSCAN(min_samples=1, metric='precomputed').fit(sims) db1_labels = db1.labels_ db1n_clusters_ = len(set(db1_labels)) - (1 if -1 in db1_labels

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Get cluster size in sklearn in python

username I am using sklearn DBSCAN to cluster data as follows. #Apply DBSCAN (sims == my data as list of lists) db1 = DBSCAN(min_samples=1, metric='precomputed').fit(sims) db1_labels = db1.labels_ db1n_clusters_ = len(set(db1_labels)) - (1 if -1 in db1_labels

Get cluster size in sklearn in python

username I am using sklearn DBSCAN to cluster data as follows. #Apply DBSCAN (sims == my data as list of lists) db1 = DBSCAN(min_samples=1, metric='precomputed').fit(sims) db1_labels = db1.labels_ db1n_clusters_ = len(set(db1_labels)) - (1 if -1 in db1_labels

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

Markerclusterer get cluster size in meters

Sushmit Chakraborty I am learning Google Maps in JavaScript. I'm following the tutorial code and so far I have a map with some markers clustered on zoom out. Here is the code - <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.

shell command to get the pixel size of an image

blue Is there a shell command to return the pixel size of an image? I'm trying to generate animated gifs starting from different gifs with different sizes using convert(for example convert -delay 50 1.gif 2.gif -loop 0 animated.gif) . The problem is that the t