From link:
Black-to-White transition is taken as Positive slope (it has a positive value) while White-to-Black transition is taken as a Negative slope (It has negative value). So when you convert data to np.uint8, all negative slopes are made zero. In simple words, you miss that edge.
So all i want is to write a function so i can keep negative gradient values. I know how to use Sobel.
Here is the sobel link where I got to know light-to-dark, dark-to-light are gradient directions, which are also referred as $+\text ve$ and $-\text ve$ directions.
IMPROVED Question: Please Suggest me a logic of the function to retain only $-\text ve$ values and clip $+\text ve$ values to zero?
My code:
Sobel(grayImg, grad, CV_16S, 0, 1, -1, BORDER_DEFAULT);
gradCpy = grad.clone();
for(uint64_t i=0; i <(gradCpy.rows); i++)
{
for(uint64_t j=0; j<(gradCpy.cols); j++)
{
if ((gradCpy.data[((gradCpy.step/gradCpy.elemSize()))*i+j]) > 0) {(gradCpy.data[(gradCpy.step/gradCpy.elemSize())*i+j]) = (int32_t)-0.0;} ///nega gradient img
//if ((gradCpy.data[((gradCpy.step/gradCpy.elemSize()))*i+j]) < 0.0) {gradCpy.data[((gradCpy.step/gradCpy.elemSize()))*i+j] = (int16_t)+0.0;} ///pos gradient img
}
}
convertScaleAbs(gradCpy, opImg2);
imshow("negative grad", opImg2);
But i am not getting expected results. As per Sobel link, I want to get edge at black-to-white that is $+\text ve$ gradient and another one at white-to-black that is $-\text ve$ gradient