Sobel Edge Detection Threshold value single vs uint8 image

5 views (last 30 days)
I have a Simulink model that does edge detection using the Edge Detection Block with the Sobel algorithm. I have found a good Threshold to get the level of detection that I want. For the application, my image source will change from single to unit8. I can not find a Threshold in uint8 that gives me the equivalent result as the one I use in single.
I made an example Simulink file and attached it here to show what I mean. On the top is my current solution, using an image in datatype single and Sobel Threshold 0.1 that gives me a good edge detection. On the bottom is my future solution where the image datatype has changed to uint8. I tried many different values for the Sobel Threshold but I can not find one that gives me a similar result as in the top path.
In the following screenshot, I show the images and detected edges:
I am aware that converting the image to datatype single would probably enable me to get the current performance, but I want to avoid that step due to memory/processing power constraints.
  4 Comments
Matthias von Andrian
Matthias von Andrian on 20 Apr 2023
Sorry, my bad. I did not screenshot the final model. I edited the screenshot in the original question to match the question. The edge result for uint8 and threshold 25 does still not match the edge result for single and threshold 0.1.

Sign in to comment.

Accepted Answer

Matthias von Andrian
Matthias von Andrian on 20 Apr 2023
I found the answer:
In the "Data Types" tab, I have to select "Same as product output" for the Accumulator.
Now I get the same edge detection result for both datatypes:

More Answers (1)

Image Analyst
Image Analyst on 20 Apr 2023
I don't know Simulink but Sobel has a fixed filter size that may not scale well with the size/width of the edges in your particular image. It would be better to use a DOG filter (difference of Gaussians). You can tailor the width of the Gaussians to optimize for the size and sharpness of edges in your image.
  1 Comment
Matthias von Andrian
Matthias von Andrian on 20 Apr 2023
The sobel block works well when the image is supplied as datatype single with pixel values from 0 to 1 and a threshold of 0.1.
For the same image supplied as datatype uint8 with pixel values from 0 to 255 and a threshold of 25, I get a completely different result. I can not find a threshold in the uint8 case that gives the same result as in the single case.
I'll add a screenshot of the original image and the detected edges in the two cases to the original question.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!