slhck / siti

Calculate Spatial Information / Temporal Information according to ITU-T P.910
Other
16 stars 6 forks source link

Border handling of Sobel filter #6

Open cosmin opened 3 years ago

cosmin commented 3 years ago

ITU-T Rec P.910 in Annex A, section A.1 defines the Sobel filter should be performed without border extension.

The calculations are performed for all 2 ≤ i ≤ N – 1 and 2 ≤ j ≤ M – 1, where N is the number of rows and M is the number of columns.

However scipy.ndimage.sobel uses a default mode of reflect. From the documentation there doesn't appear to be a mode for computing on only the valid range without border extension, therefore a mask should probably be applied to the output to discard the outer 1 pixel border from the results.

This has a minor impact on the resulting numerical values for SI, but it's probably a good idea to correct this nonetheless for consistency.

slhck commented 3 years ago

This should be fixed by #7 — could you please have a look? I'm simply discarding the outer 1 px border of the gradient magnitude before calculating the standard deviation.

Indeed the sobel function doesn't allow changing the behavior. One could implement it with lower-level functions (convolve) but I suppose this amounts to the same.

cosmin commented 3 years ago

LGTM. I think discarding the outer 1px is probably best solution, unless someone adds valid option to scipy.ndimage.sobel