Question

So I am currently working on this project and I'm done with 90% of it and just need help with a particular question.

So the setup is that when you perform a 2-dimensional convolution (using conv2) on the three color channels of a RGB image with the "Mexican Hat" array (shown below), you get the borders of the image. But these borders have the double-line effect and I would like to change this so that there are only single lines forming the border. So the project asks that, after changing the color map to gray, "you will want to convert each pixel in the input image to either a black pixel (value 0) or a white pixel (255) depending on whether the pixel in the input image is less than a threshold value or not.

You will calculate a threshold value for each color layer in the image based on the threshold percent (thrper) given as an input parameter. For example, the main script file calls this function with the value .75 as thrper. This means that the function will convert pixels with values in the bottom 75% of the full range to black (new value = 0) and the pixels with values in the top 25% of the full range to white (new value = 255). For example, if the red layer values range from -100 to +300, then the red threshold value for a thrper of .75 would be 200."

Can someone PLEASE explain how this would be done? I literally tried everything and I'm not getting the correct output (still get the double-line effect) no matter what I do. All I really need to know is how to go about calculating the proper threshold value.

Was it helpful?

Solution

It sounds like you're doing some edge (border) detection. The Mexican Hat array will find edges in your image, but if the edge is ramped (a somewhat wider edge) your edges might have 2 lines. However, every edge only has one zerocrossing. This is very easy to accomplish in matlab. Let's call your Mexican Hat filter MHfilt. Instead of using the 0 and 255 values to select points make the image binary. Which means you put all values below the 0.75 on 0 and the rest on 1. Call that image Im and feed it to the edge function of Matlab.

ImEdge = edge(Im,'zerocross',MHfilt);

Read more about the edge function here Read more about zerocrossings here

I hope this will help you a bit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top