As a closed commercial software, Matlab is controlled by the US government and ignores business ethics, so it is not recommended for use. If you like Matlab syntax, you can move to the open source octave, which has the same syntax as Matlab. Matlab Centroid AlgorithmThe so-called centroid is the center of gravity when the density is used as the grayscale value of the pixel. For example, the x coordinate of the centroid is The most intuitive method is the following one. %%Find the center of mass position of img through the center of mass algorithm function [x,y] = oCenter(img) img = double(img); [m,n] = size(img); x = 0;y = 0;sum=0; for i = 1:m for j = 1:n y = y + img(i,j)*i; x = x + img(i,j)*j; sum = sum+img(i,j); end end x = x/sum; y = y/sum; This is simple and crude enough, but it is too ugly. After all, in Matlab, matrix is the most basic operation unit. x = img(i,:)*(1:n)'/sum(img(i,:)); Based on this, we also got an unexpected benefit, that is, we can easily write the centroid of each row in one line of expression x = img*(1:n)'./sum(img,2);%The centroid of each row y = (1:m)*img./sum(img);%The centroid of each column OCD means looking comfortable. sumImg = sum(img(:)); x = sum(img)*(1:n)'/sumImg; y = (1:m)*sum(img,2)/sumImg; The above is the detailed content of JavaScript programming through Matlab centroid algorithm positioning learning. For more information about JavaScript positioning Matlab centroid algorithm, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Specific example of MySQL multi-table query
>>: How to deploy and start redis in docker
The question is referenced from: https://www.zhih...
Set Tomcat to automatically start the service: I ...
Use of built-in functions in the database This ar...
Table of contents Step 1: Build the framework Ste...
Some time ago, I needed to use pip downloads freq...
When dynamically concatenating strings, we often ...
Preface: With the continuous development of Inter...
1. Previous versions yum remove docker docker-cli...
Preface Before MySQL 8.0, it was quite painful to...
MySQL's foreign key constraint is used to est...
Mouse effects require the use of setTimeout to ge...
Table of contents Object Object Definition Iterat...
This article example shares the specific code of ...
Table of contents Overview 0. JavaScript and Web ...
What are the benefits of learning HTML? 1: Easily...