Jump to content
  • Advertisement
Sign in to follow this  
jkh13

Normalising a value in HLSL

This topic is 2607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!