adrelino / variational-depth-from-focus

Implementation of "Variational Depth from Focus Reconstruction" [Moeller 2015]
GNU General Public License v2.0
56 stars 23 forks source link

How to explain the output depth data? #4

Closed scimg closed 7 years ago

scimg commented 7 years ago

I tried to parse the .exr file and to save the "res" mat directly, but could not understand the meaning of the output. It seems that the range of the output data has something to do with -minVal and -maxVal. How to convert the output into the index of the layer?

adrelino commented 7 years ago

The value of MLAP(k,i,j) is a measure for the contrast at pixel (i,j) in the image with index k in the sequence.

Lets say we have a stack of 8 images, then we get 8 such contrast measures for each pixel. Then we fit a smooth curve, in this case a polynomial onto these points, which approximates them.

The argmax of this polynomial is now a real! number between [0, 8], because the maximum can occur at non integer locations. I think we now just linearly scale this range into the range [minVal, maxVal].

So you could just try to reverse this linear mapping, i.e.: k* = (res(i,j) - minVal)/(maxVal-minVal) klower = floor(k) kupper = ceil(k)

and check if all the values are in the range [0,8]?

mngKd commented 7 years ago

Hi @scimg,

you are right - the output range is scaled to [minVal,maxVal]. If I remember correctly, this has to do with the original paper, since the Matlab figures were also scaled from -10 to 10. You can checkout the branch 'depthMapFix', which then uses min- and maxValue from the actual resulting depthmap. Currently I can not give you any more information than @adrelino, it's been a while we wrote this code.

scimg commented 7 years ago

@adrelino Do you mean that if the stack has K images, and the value in the output is res(x,y), then the actual index of (x,y) is k = K * (res(x,y) - minVal) / (maxVal - minVal) ?

By the way, is there any threshold to ignore weak textures? Since I find that the results of some regions are always zero.

adrelino commented 7 years ago

@scimg sorry, you are right, I forgot the multiplication by K. what I was referring to was only the initialization of the variational admm algorithm. In the end, the regularizer term should smooth away large jumps in the depth values by considering neighbouring pixels.

However, if there is no texture in a large image region, I think the result will be quite arbitrary, since the polynomial will be quite flat, with arbitrary maxima.

scimg commented 7 years ago

@adrelino @mngKd Thank you! I will try.