Question

My goal is to make a ridge(mountain)-like shape from the given line. For that purpose, I applied the gaussian filter to the given line. In this example below, one line is vertical and one has some slope. (here, background values are 0, line pixel values are 1.)

Given line:

http://me.berkeley.edu/~young/lines.png

Ridge shape:

http://me.berkeley.edu/~young/ridges.png

When I applied gaussian filter, the peak heights are different. I guess this results from the rasterization problem. The image matrix itself is discrete integer space. The gaussian filter is actually not exactly circular (s by s matrix). Two lines also suffer from rasterization.

How can I get two same-peak-height nice-looking ridges(mountains)? Is there more appropriate way to apply the filter? Should I make a larger canvas(image matrix) and then reduce the canvas by interpolation? Is it a good way?

Moreover, I appreciate if you can suggest a way to make ridges with a certain peak height. When using gaussian filter, what we can do is deciding the size and sigma of the filter. Based on those parameters, the peak height varies.

For information, image matrix size is 250x250 here.

Was it helpful?

Solution

You can give a try to distance transform. Your image is a binary image (having only two type of values, 0 and 1). Therefore, you can generate similar effects with distance transform.

%Create an image similar to yours
img=false(250,250);
img(sub2ind(size(img),180:220,linspace(20,100,41)))=1;
img(1:200,150)=1;

%Distance transform
distImg=bwdist(img);
distImg(distImg>5)=0;  %5 is set manually to achieve similar results to yours
distImg=5-distImg;   %Get high values for the pixels inside the tube as shown 
                     %in your figure
distImg(distImg==5)=0;   %Making background pixels zero

%Plotting
surf(1:size(img,2),1:size(img,1),double(distImg));

To get images with certain peak height, you can change the threshold of 5 to a different value. If you set it to 10, you can get peaks with height equal to the next largest value present in the distance transform matrix. In case of 5 and 10, I found it to be around 3.5 and 8.

Again, if you want to be exact 5 and 10, then you may multiply the distance transform matrix with the normalization factor as follows.

normalizationFactor=(newValue-minValue)/(maxValue-minValue) %self-explanatory

Only disadvantage I see is, I don't get a smooth graph as you have. I tried with Gaussian filter too, but did not get a smooth graph.

My result: enter image description here

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