开发者

Comparing image on how much degrees tilted

I have an problem as seen below the one on top is the original image the one on the bottom is titlted to the left 90 degrees. Is there a way to calculate the change开发者_如何学运维 in angle. I have tried Hough's Transform, I can detect the location, however I cannot detect the angel that is changed. Is there an alternative to detect the degreeschanged.

Comparing image on how much degrees tilted

Comparing image on how much degrees tilted


I've done this before using a Symmetric Phase-Only Matched Filter. It was actually for fingerprint recognition, allowing rotation and scaling. Unfortunately, it's pretty complicated. You need to be comfortable with how to compute an FFT and with similar-level math. I did not do it in C#, but in MATLAB (and in synthesizable Verilog, but that's another story altogether). I would recommend using MATLAB or a similar math package first to be sure you have the algorithm right.

Hopefully, though, someone has already implemented this algorithm in a .NET image processing library somewhere.

The paper I used was the following. It is more math-based than algorithmic, so it will take some work to convert it to code:

Qin-Sheng Chen; Defrise, M.; Deconinck, F. "Symmetric phase-only matched filtering of Fourier-Mellin transforms for image registration and recognition," Pattern Analysis and Machine Intelligence, IEEE Transactions on , vol.16, no.12, pp.1156-1168, Dec 1994

Abstract: Presents a new method to match a 2D image to a translated, rotated and scaled reference image. The approach consists of two steps: the calculation of a Fourier-Mellin invariant (FMI) descriptor for each image to be matched, and the matching of the FMI descriptors. The FMI descriptor is translation invariant, and represents rotation and scaling as translations in parameter space. The matching of the FMI descriptors is achieved using symmetric phase-only matched filtering (SPOMF). The performance of the FMI-SPOMF algorithm is the same or similar to that of phase-only matched filtering when dealing with image translations. The significant advantage of the new technique is its capability to match rotated and scaled images accurately and efficiently. The innovation is the application of SPOMF to the FMI descriptors, which guarantees high discriminating power and excellent robustness in the presence of noise. This paper describes the principle of the new method and its discrete implementation for either image detection problems or image registration problems. Practical results are presented for various applications in medical imaging, remote sensing, fingerprint recognition and multiobject identification


You can also rotate second image in a loop by constant angle and calculate RMSE between two images in each iteration. Matching angle will be where RMSE is minimum.

Here is powershell script which implements this idea with ImageMagick:

# convert images to equal sizes for pixel by pixel comparision
convert.exe p1.png -resize 73x73! p1.png
convert.exe p2.png -resize 73x73! p2.png

# initialize variables
$min_rmse = 1.0
$degrees_rotated = -1.0

# rotate second image by 10 degrees in each iteration
# and after that measure RMSE between first image and second rotated image
for ($i=0; $i -le 350; $i+=10) {
    convert.exe p2.png -rotate $i tmp.png
    convert.exe tmp.png -resize 73x73! tmp.png
    $rmse = compare.exe -metric rmse p1.png tmp.png diff.png 2>&1
    $rmse = ([string] $rmse).split(" ")[1]
    $rmse = $rmse.replace("(","")
    $rmse = [double] $rmse.replace(")","")

    # find rotation angle where RMSE is minimal
    if ($rmse -lt $min_rmse) {
        $min_rmse = $rmse
        $degrees_rotated = $i
    }
}

Write-Host "two images are most similar when second image is rotated by $degrees_rotated deg (rmse is $min_rmse)"
Write-Host "Press any key to exit ..." 
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Hope that helps.
p.s. According to wiki RMSE between two vectors can be calculated in two different ways. I don't know which one is implemented in ImageMagick as

compare.exe -metric rmse
command, but for sure this can be determined by asking IM developers or by trial-and-error method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜