HistomicsTK icon indicating copy to clipboard operation
HistomicsTK copied to clipboard

compute_haralick_features works incorrectly when `im_intensity` is a float with [0, 1] values

Open idc9 opened this issue 2 years ago • 1 comments

My understanding of compute_haralick_features is that you can provide im_intensity as a 2d array of float intensity values between 0 and 1. However, as written, the function will always cast im_intensity to an int in this line. This leads to incorrect behavior for [0,1] intensity valued images i.e. these will be binarized, which is not what we want to do. For example, most of the Haralick features end up being constant.

A simple fix would be to simply remove the .astype(np.uint8) i.e.

subImage = im_intensity[minr:maxr+1, minc:maxc+1]

I'm not sure what the purpose of casing subImage to np.uint8 -- is there a problem with removing this?

idc9 avatar Jul 08 '22 15:07 idc9

@idc9 this is addressed by #948 . We'll get this merged after the reviewer returns from travel.

cooperlab avatar Jul 09 '22 02:07 cooperlab

Hi, just wanted to add here as the PR that was mentioned seems to still be open. I've been using the haralick features function and I ran into a related issue. My input arrays are uint16 array and the current behaviour causes overflow once the arrays are cast to uint8 without any previous rescaling of the intensities.

adrtsc avatar Mar 15 '24 12:03 adrtsc

I've also encountered this problem, and at the very least it should be added in the documentation that the image has to be scaled to uint8 for compute_haralick_features to work properly.

Aleksandr-Enin avatar Mar 28 '24 11:03 Aleksandr-Enin