Normalising a value in HLSL

Started by
0 comments, last by jameszhao00 12 years, 6 months ago
Hi, I have been implementing the canny edge detection algorithm using HLSL and XNA and I noticed that my edges coming out at the end are not 1 pixel width as they are supposed to be. My passes are as follows (they are all pixel shaders):

1 - 2 passes of gaussian (vertical + horizontal)
2 - Sobel
3 - Canny edge

I noticed that the sobel pass is generating an image with lots of the pixel intensities > 1 which I am guessing is causing the canny edge detection to pick them all up as when the texture enters the canny stage they are all clamped to 1. The question is how do I go about normalising the pixel intensities from the sobel pass so they lie within the range [0-1]. I am not very experienced with HLSL (this is my first time writing a shader) and I couldn't find a way to store the max intensity of all the pixels in order to perform normalisation of intensities after the sobel pass. Is there a way to access a global variable using HLSL?

edit: I thought of dividing the intensity by 10 at the end of the sobel pass and multiplying it back to the original value during the canny pass but I wanted to have the threshold value at the canny stage between 0 and 1 and doing the division means that the threshold would mean different things based on the image.
Advertisement

Hi, I have been implementing the canny edge detection algorithm using HLSL and XNA and I noticed that my edges coming out at the end are not 1 pixel width as they are supposed to be. My passes are as follows (they are all pixel shaders):

1 - 2 passes of gaussian (vertical + horizontal)
2 - Sobel
3 - Canny edge

I noticed that the sobel pass is generating an image with lots of the pixel intensities > 1 which I am guessing is causing the canny edge detection to pick them all up as when the texture enters the canny stage they are all clamped to 1. The question is how do I go about normalising the pixel intensities from the sobel pass so they lie within the range [0-1]. I am not very experienced with HLSL (this is my first time writing a shader) and I couldn't find a way to store the max intensity of all the pixels in order to perform normalisation of intensities after the sobel pass. Is there a way to access a global variable using HLSL?

edit: I thought of dividing the intensity by 10 at the end of the sobel pass and multiplying it back to the original value during the canny pass but I wanted to have the threshold value at the canny stage between 0 and 1 and doing the division means that the threshold would mean different things based on the image.


Use a float texture.

By they way, does threshold(.1 * 10 * i) not equal threshold(i) for any meaning of i?

This topic is closed to new replies.

Advertisement