Get the App
SLTechnology News&Howtos  ›  Development  › 

How to locate through Matlab centroid algorithm in JavaScript programming

Shulou Source: shulou.com Published: 2022-06-03 03:16:16 09月29日 Update

This article introduces the relevant knowledge of "how to locate JavaScript programming through the Matlab centroid algorithm". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

Matlab centroid algorithm

As a closed commercial software, Matlab is influenced by the US government and ignores business ethics, so it is not recommended to use it. If you like the Matlab syntax, you can move to the open source octave, whose syntax is exactly the same as matlab.

Matlab centroid algorithm

The so-called center of mass is the center of gravity when the density is the grayscale value of a pixel, for example, the x coordinate of the center of mass is

The most intuitive way is the following way.

%% find the centroid position of img by centroid algorithm function [XMagi y] = oCenter (img) img = double (img); [mMae n] = size (img); x = 0 for y = 0 img m for j = 1RV n y = y + img (iMagnej) * I; x = x + img (iMagnej) * j; sum= sum+img (iMagazine j); endendx = xbot sumscape = y/sum =

This is simple and rough enough, but it is too ugly. After all, in Matlab, the matrix is the most basic unit of operation.

And it is true that the same array is used repeatedly in the process of summation. For row I, each column is the same as 1pm 2pm 3. Multiply and sum, that is, the dot product of the I-th line vector and the vector [1]. So regardless of the whole picture, the centroid of the line I vector can be written out relatively easily.

X = img (iPermine:) * (1img n)'/ sum (iMagne:))

Based on this, we also get a windfall, that is, we can easily write the centroid of each line with an one-line expression.

X = img* (1 img./sum n)'. / sum (img,2);% centroid of each row y = (1 img,2 m) * centroid (img);% centroid of each column

Obsessive-compulsive disorder means you look comfortable.

Accordingly, the centroid of the picture as a whole can be written as

SumImg = sum (img (:)); x = sum (img) * (1sum n)'/ sumImg;y = (1sum m) * sum (img,2) / sumImg; "how to locate through the Matlab centroid algorithm" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Centroid algorithm line vector location programming same content business picture that is more knowledge grammar process practical comfortable unexpected intuitive rude Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MariaDB Microsoft macOS