MATLAB exercise program (force field transformation)

Source: Internet
Author: User

When each pixel in an image is regarded as a mass star, the gray value of the pixel is equivalent to the mass of the star. The law of gravitation is used to obtain the "force" of each pixel from other pixels and the force field image.

The formula is the formula of universal gravitation in middle school, but it is a vector field. Therefore, the force of each pixel is not a simple superposition, but a vector summation.

It seems that this force field transformation is used to recognize the ears.

Here is also the partial force field for template size. I ran the global force field for one day and the results were not satisfactory.

Related code:

Main. m

Clear all; close all;clc;r%3%img%imread('lena.jpg '); IMG = double (IMG); [m n] = size (mat2gray (IMG); imgn = zeros (m + 2 * r + 1, n + 2 * r + 1); imgn (R + 1: m + R, R + 1: N + R) = IMG; imgn (1: R, R + 1: N + R) = IMG (1: R, 1: N); imgn (1: m + R, N + R + 1: n + 2 * r + 1) = imgn (1: m + R, N: N + r); imgn (m + R + 1: m + 2 * r + 1, R + 1: n + 2 * r + 1) = imgn (M: m + R, R + 1: n + 2 * r + 1); imgn (1: m + 2 * r +: R) = imgn (1: m + 2 * r + 1, R + * r); f_field = imgn; for I = 1 + R: m + R for j = 1 + R: N + R f = 0; for P = I-r: I + R for q = J-R: J + R if I ~ = P & J ~ = Q p0 = [I j]; lev= [I + 10 J]; P1 = [p q]; Jiao = multi_jiao (P1, lev, P0 ); % The following four steps determine the angle between the vector and the horizontal vector through the angle theorem and the cross product flag = multi (P1, lev, P0); Jiao = xiangxian (Jiao, flag ); jiao = Mod (Jiao, 360); value = cos (Jiao * PI/180); % determines the weight by cosine. The force field is a vector field F = F + imgn (I, j) * imgn (p, q)/SQRT (I-p) ^ 2 + (J-q) ^ 2) * value; % law of universal gravitation end f_field (I, j) = F; end endfigure; f_field = f_field (R + 1: m + R, R + 1: N + r); imshow (mat2gray (f_field ));

Multi_jiao.m

Function Re = multi_jiao (P1, P2, P0) % judgment <P10, P20> Angle X = 1; y = 2; vec1 = p1-p0; vec2 = p2-p0; re = ACOs (dot (vec1, vec2)/(norm (vec1) * norm (vec2) * 180/PI; End

Multi. m

Function Re = multi (P1, P2, P0) % P10, P20 cross product, obtain positive and negative X = 1; y = 2; Re = (p1 (X) -P0 (x) * (P2 (y)-P0 (y)-(p1 (y)-P0 (y) * (P2 (X) -P0 (x); End

Xiangxian. m

function re=xiangxian(jiao,flag)       if flag>0        re=360-jiao;    else        re=jiao;                end                 end

The following figure shows the running effect:

Source image

Local force field of 7*7

The simple Scalar summation seems to be a pretty cool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.