Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then use a tilt formula and then limit it to what the peak values would allow.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix in Mat = heat map. also gives function size of source. in point = x,y point from minMaxLoc or any other point you want to explore in Polarity = Let this function know if we want large or small values in Method = what algorithm to use since mine won't be the best for every application. out Float x,y returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then use a tilt formula and then limit it to what the peak values would allow.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix minMaxLocSubPix

in Mat = heat map. also gives function size of source.
  in point = x,y point from minMaxLoc or any other point you want to explore
      in Polarity = Let this function know if we want large or small values
  in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y x,y

returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then use a tilt formula and then limit it to what the peak values would allow.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPixminMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y

x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

click to hide/show revision 4
added summary question

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then use a tilt formula and then limit it to what the peak values would allow.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

In summary: My question is... Should I take the time to make the code I am writing generic enough to include in the library? I am also looking for any other examples or suggestions.

click to hide/show revision 5
More links to info.

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then use a tilt formula and then limit it to what the peak values would allow.then... edit: I am thinking that a parabola fit will work better.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

Edit: Here is a 2009 paper describing a more accurate method. http://opticalengineering.spiedigitallibrary.org/article.aspx?articleid=1089241

In summary: My question is... Should I take the time to make the code I am writing generic enough to include in the library? I am also looking for any other examples or suggestions.

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then... edit: I am thinking that a parabola fit will work better.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

Edit: Here is a 2009 paper describing a more accurate method. http://opticalengineering.spiedigitallibrary.org/article.aspx?articleid=1089241

Here is my current code. It works, but has not been tested much. http://www.longrange.net/Temp/CV_SubPix.h http://www.longrange.net/Temp/CV_SubPix.cpp

In summary: My question is... Should I take the time to make the code I am writing generic enough to include in the library? I am also looking for any other examples or suggestions.Edit: I did end up making it along the lines of the library, however I am not sure how to suggest including it once it's tested.

getting subpixel with MatchTemplate

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then... edit: I am thinking that a parabola fit will work better.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

Edit: Here is a 2009 paper describing a more accurate method. http://opticalengineering.spiedigitallibrary.org/article.aspx?articleid=1089241

Here is my current code. It works, but has not been tested much. Edit: 4/28/2014 I found a bug and updated it. http://www.longrange.net/Temp/CV_SubPix.h http://www.longrange.net/Temp/CV_SubPix.cpp

In summary: My question is... Should I take the time to make the code I am writing generic enough to include in the library? Edit: I did end up making how do I add it along the lines of the library, however I am not sure how to suggest including it once it's tested.to the library to share with others?