I have an irregular region of interest from an MRI image which I have selected. I would like to do co-occurrence analysis on the image using skimage.feature.greycomatrix
library. However, my ROI is irregular in shape. Keeping 0's in the numpy array of the image would result in an incorrect grey co-occurrence analysis and I have made them NaN
's. However, the greycomatrix
is unable of analyzing a numpy array with NaN
's. Has anyone experienced this problem or have a solution?
Asked
Active
Viewed 487 times
1

Tonechas
- 13,398
- 16
- 46
- 80

David McCoy
- 81
- 7
-
I don't think *python* itself has `greycomatrix`. Do you mean [`skimage.feature.graycomatrix` from `sckit-image`](http://scikit-image.org/docs/dev/auto_examples/plot_glcm.html)? If not, which image processing library are you currently getting the function from? – Warren Weckesser Oct 25 '16 at 04:10
-
Hi Warren, yes I am importing skimage.feature.greycomatrix. Therefore, I am wondering if there is a way to use this library on images which include NaN's/irregular ROIs or if there is another greycomatrix library that can be used. I remember reading that matlab can handle NaN's in the calculations. Thanks. – David McCoy Oct 25 '16 at 17:09
1 Answers
1
In regards to this question, it doesn't seem as if the greycomatrix library in skimage can handle NaN values or irregular shapes but only does 'whole-image' analysis.
To get past this, I chose to do the image analysis in 'R' by exporting the matrix as a csv then importing it in R using:
import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
import pandas.rpy.common as com
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
ro.r("Axial_Data <- read.csv('axial_slice_ROI.csv', header = FALSE)")
print(ro.r('max(Axial_Data, na.rm = TRUE)'))
ro.r('Axial_Data <- as.matrix(Axial_Data)')
ro.r("library(radiomics)")
ro.r("library('glcm')")
ro.r("library('raster')")
## get first order statistics
ro.r("first_order <- calc_features(Slice_Data)")
## GLCM
ro.r("textures <- glcm(raster(Axial_Data), na_opt = 'any', shift=list(c(0,1),c(1,1), c(1,0), c(1,-1)))")
Hope that helps anyone who may have similar issues in the future.
Cheers,

David McCoy
- 81
- 7