Ask Your Question
0

How to create peaks at coordinates

asked 2016-03-22 09:08:58 -0600

NDLeo gravatar image

updated 2016-03-24 05:57:15 -0600

Hello, I have a problem with creating a peaks in image at some coordinates in Python. For example: x = [20,20,58] y = [30,60,32] z = [1,0.5,0.8]

where x, y are coordinates and z is value of height of the peak. The steepness of the peak should be linear or Gaussian (it doesn't matter). The most important thing is, the peak should not overlap completely. That means, if I have two points near each other and the first one have value 1 and the second 0.2, the higher peak should not overlap the second, but there will be some interpolation between them(similar as I overlap two radial gradients with alpha channel 1 in middle and 0 on the edge).

It should looks like: image description

EDIT

I tried to draw it in 1D system.

image description

As you can see, the green lines represent the final solution. If two peaks are too close to each other, the lower peak makes some interpolation with the higher one.

I will be really grateful, if you can help me. Best regards, Andy

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-03-24 06:34:08 -0600

kbarni gravatar image

I think an easy way would be to smooth the image iteratively with a one-pixel diameter kernel, and only for the non-zero pixels.

Pseudocode:

repeat:
    for each pixel>0
        for each neighbor=0
            neighbor=pixel*0.8

Like this, you will have a small valley even between close points, but sometimes the transition won't be smooth.

Another way would be to create a gaussian blurred image and another image where you interpolate all the points (using for example a Delaunay triangulation). Then, for each pixel take the lower value.

gauss=gaussianblur(points,sigma)
delaunay=triangulate(points)
result=min(gauss, dealunay)

The disadvantage of this approach is that the triangulation isn't implemented in OpenCV (you have to do it yourself), and in some cases you can get artifacts.

edit flag offensive delete link more

Comments

Thank you, I used the Delaunay triangulation. This method is already implemented in OpenCV as cv2.Subdiv2D().

NDLeo gravatar imageNDLeo ( 2016-03-31 05:03:14 -0600 )edit
0

answered 2016-03-22 16:01:48 -0600

Tetragramm gravatar image

I think this does what you want, but it's a bit unclear.

Create two empty images, one for work, one for results, both should be float type.

Zero the work image. Place a single pixel of <point height=""> in the appropriate place in the work image. Gaussian Blur. Add the work image to the result image.

Once you have done this for all the points, normalize the results image.

If this doesn't do what you want, then I'm not quite sure what you mean by "not overlapping".

edit flag offensive delete link more

Comments

I edited the post and add some picture of the solution.

NDLeo gravatar imageNDLeo ( 2016-03-24 05:54:56 -0600 )edit

Hmm, Is the green line the solution you want? If so, just replace the Add step with a Max step in my solution.That way it keeps whichever is higher. If the transition is two abrupt, you can smooth it a bit more (use a small size box filter should be fine).

Tetragramm gravatar imageTetragramm ( 2016-03-24 07:04:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-22 09:08:58 -0600

Seen: 410 times

Last updated: Mar 24 '16