I am trying to apply Haralick textures to a SAR image (float32). As far as I know, the image first needs to be quantized to a reasonable bit depth prior to calculate the co-ocurrence matrix. In the original paper, Haralick proposes using a "equal probability quantizer". As far as I know is the algorithm employed by Mathlab "imquantize". I have been looking for a pre-existing python/numpy implementation (no success).
I also have reading pre-existing java code from ESA SNAP. As far I know histogram calculations would be straightforward with numpy, but if I understand correctly, every pixel is assigned a "level/histogram bin" using bisection search, so I do not see any straightforward way to properly vectorize the code.
EDITED after this point ===================
import numpy as np def eqProbQuant(image, levels=32): # Sort the pixels by value sorted_image = np.sort(image) # Get the pixel count pixel_count = sorted_image.shape # Get the number of pixels per bin samples_per_bin = int(pixel_count/levels) # Get locations where the bin would change edge_samples = np.arange(levels+1) * samples_per_bin # Get the values at those locations (bin edges) bin_edges = sorted_image[edge_samples] # Use the values to apply quantization quantized = np.digitize(image, bin_edges) return quantized
If possible, I would like to know if this code would apply the algorithm correctly (I have very little experience with signal processing)