4
$\begingroup$

I am trying to use a distance transform as a descriptor to encode silhouettes in order to do a shape recognition task. It is clear that distance transform distribution is invariant under rotation and translation. Here are some examples that demonstrate this:

(Translation test)

im1

im2

 distransform1 = ImageData[DistanceTransform[im1]] // Flatten;
    distransform2 = ImageData[DistanceTransform[im2]] // Flatten;
    N[BinCounts[distransform1, {0, 20, 1}]/Length[distransform1]]
    (*{0.9603, 0.0115, 0.0104, 0.0064, 0.0045, 0.004, 0.0019, 0.0008,
0.0002, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}*)
    N[BinCounts[distransform2, {0, 20, 1}]/Length[distransform2]]
    (*{0.9603, 0.0115, 0.0104, 0.0064, 0.0045, 0.004, 0.0019, 0.0008,
0.0002, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}*)

(Test of rotation)

 im3 = ImageTransformation[im1, RotationTransform[5 Degree]]
 distransform3 = ImageData[DistanceTransform[im3]] // Flatten;
   N[BinCounts[distransform3, {0, 20, 1}]/Length[distransform3]]
    (*{0.9601, 0.0121, 0.0105, 0.0066, 0.0044, 0.0037, 0.0017, 0.0009, 0., \
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}*)

(Test of scaling)

im4 = ImageTransformation[im1, # .75 &]
     distransform4 = ImageData[DistanceTransform[im4]] // Flatten;
     N[BinCounts[distransform4, {0, 20, 1}]/Length[distransform1]]
        (*{0.9296, 0.0154, 0.0143, 0.0103, 0.0088, 0.0087, 0.0044, 0.0039, \
0.0029, 0.0013, 0.0004, 0., 0., 0., 0., 0., 0., 0., 0., 0.}*)

I'm trying to calculate the distribution by taking only the non-zero distances normalized by the number of white pixels. But this isn't working and I don't know what is wrong.

$\endgroup$
  • $\begingroup$ For this to make sense, maybe you could define im3 and distransform4. $\endgroup$ – bill s Nov 5 '14 at 4:38
  • $\begingroup$ @bills, I edited my code. It was mistype $\endgroup$ – BetterEnglish Nov 5 '14 at 6:18
  • $\begingroup$ The number of white pixels is not directly proportional to the scale factor, it is proportional to the square of it. Try normalizing by the maximum distance instead. $\endgroup$ – Rahul Nov 5 '14 at 8:00
  • $\begingroup$ @RahulNarain, I have tried by normalizing by the max value of distances by applying the ImageAdjust[] before I posted the question, but it does not work!! $\endgroup$ – BetterEnglish Nov 5 '14 at 16:11
  • $\begingroup$ @RahulNarain, when i normalize by the max value, distances will be between 0 and 1 and then I change the arguments of Bincounts[vec,{0,1,.1}] $\endgroup$ – BetterEnglish Nov 5 '14 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.