Moving target extraction method and device
Technical Field
The present invention relates to the field of image processing, and in particular, to a method and an apparatus for extracting a moving object.
Background
In the process of processing the image, it is often necessary to extract a moving object in the image. Existing moving object extraction schemes typically include:
1. determining a matrix model corresponding to the image by using an RPCA (robust principal component analysis) algorithm, wherein the matrix model comprises a foreground matrix and a background matrix, and the foreground matrix is a matrix corresponding to the moving target;
2. performing iterative solution on the determined matrix model by using an Alternating Direction Method (ADM);
3. and after the iteration process is finished, determining a foreground matrix in the matrix model, and further extracting the moving target in the image.
In the scheme, the ADM algorithm is used for iteration, the convergence speed is low, the iteration times are multiple, the speed of the whole iteration process is low, and the consumed time is long.
Disclosure of Invention
The embodiment of the invention aims to provide a moving object extraction method and a moving object extraction device, which can improve the iteration speed and shorten the time consumed by iteration.
In order to achieve the above object, an embodiment of the present invention discloses a moving object extraction method, including:
determining a matrix model corresponding to the image by using an analysis algorithm;
performing iterative processing on the matrix model, wherein each iterative process comprises the following steps:
determining a foreground matrix, a constraint multiplier and a background matrix which are currently corresponding to the matrix model;
updating the foreground matrix according to the foreground matrix, the constraint multiplier and the background matrix;
updating the constraint multiplier once according to the updated foreground matrix, the constraint multiplier and the background matrix;
updating the background matrix according to the updated foreground matrix, the constraint multiplier after the primary update and the background matrix;
carrying out secondary updating on the constraint multiplier according to the updated foreground matrix and background matrix and the once updated constraint multiplier;
judging whether the constraint multiplier after the secondary updating meets a preset error condition, if not, carrying out the next iteration process, and if so, finishing the iteration process;
and after the iteration process is finished, extracting a moving target in the image according to an iteration result, wherein the moving target corresponds to a foreground matrix in the iteration result.
Optionally, the step of updating the foreground matrix according to the foreground matrix, the constraint multiplier, and the background matrix may include:
updating the foreground matrix using the following equation:
wherein x represents the foreground matrix, y represents the background matrix, Z represents the constraint multiplier, K represents the number of iterations, RM*NRepresenting a domain, L representing a Lagrangian function;
the step of updating the background matrix according to the updated foreground matrix, the constraint multiplier updated once, and the background matrix may include:
updating the background matrix using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, Z represents a constraint multiplier, K represents an iteration number, and Z represents a number of iterationsK+1/2Representing the constraint multiplier, R, after an updateM*NRepresenting the domain of definition and L representing the lagrangian function.
Optionally, the step of updating the constraint multiplier once according to the updated foreground matrix, the constraint multiplier, and the background matrix may include:
updating the constraint multiplier once using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
after one time updating of the representationZ, γ represents an iteration step parameter, β represents an equalization parameter;
the step of updating the constraint multiplier for the second time according to the updated foreground matrix and background matrix and the updated constraint multiplier for the first time may include:
updating the constraint multiplier twice using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
represents Z, Z after one update
K+1And Z after the second updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter.
Optionally, the step of determining whether the constraint multiplier after the second updating meets the preset error condition may include:
carrying out error operation on the constraint multiplier after the secondary updating to obtain an error parameter;
and judging whether the error parameter is within a preset error range, if so, indicating that the constraint multiplier after the secondary updating meets a preset error condition.
Optionally, the step of performing error operation on the secondarily updated constraint multiplier to obtain an error parameter may include:
performing an error operation on the twice updated constraint multiplier using the following equation:
ey(yK+1,β)=yK+1-Py[yK+1-β(g(yK+1)-ZK+1)],
wherein e is
y(y
K+1Beta) an error parameter, x a foreground matrix, y a background matrix, Z a constraint multiplier, K an iteration number, beta an equalization parameter,
P
y[y
K+1-β(g(y
K+1)-Z
K+1)]representing the projection from the domain to y.
In order to achieve the above object, an embodiment of the present invention further discloses a moving object extracting apparatus, including:
the determining module is used for determining a matrix model corresponding to the image by utilizing an analysis algorithm;
an iteration module comprising:
the determining submodule is used for determining a foreground matrix, a constraint multiplier and a background matrix which correspond to the matrix model at present;
the first updating submodule is used for updating the foreground matrix according to the foreground matrix, the constraint multiplier and the background matrix;
the second updating submodule is used for updating the constraint multiplier once according to the updated foreground matrix, the constraint multiplier and the background matrix;
the third updating submodule is used for updating the background matrix according to the updated foreground matrix, the constraint multiplier after the first updating and the background matrix;
the fourth updating submodule is used for carrying out secondary updating on the constraint multiplier according to the updated foreground matrix and background matrix and the once updated constraint multiplier;
the judgment submodule is used for judging whether the constraint multiplier after secondary updating meets a preset error condition, if not, the determination submodule is triggered, and if so, the extraction module is triggered;
and the extraction module is used for extracting the moving target in the image according to the iteration result, wherein the moving target corresponds to the foreground matrix in the iteration result.
Optionally, the first update sub-module may be specifically configured to:
updating the foreground matrix using the following equation:
wherein x represents the foreground matrix, y represents the background matrix, Z represents the constraint multiplier, K represents the number of iterations, RM*NRepresenting a domain, L representing a Lagrangian function;
the third update sub-module may be specifically configured to:
updating the background matrix using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, Z represents a constraint multiplier, K represents an iteration number, and Z represents a number of iterationsK+1/2Representing the constraint multiplier, R, after an updateM*NRepresenting the domain of definition and L representing the lagrangian function.
Optionally, the second update sub-module may be specifically configured to:
updating the constraint multiplier once using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
z after one-time updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter;
the second update sub-module may be specifically configured to:
updating the constraint multiplier twice using the following equation:
where x represents the foreground matrix and y represents the backgroundMatrix, C represents the original matrix corresponding to the image, Z represents the constraint multiplier, K represents the number of iterations,represents Z, Z after one updateK+1And Z after the second updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter.
Optionally, the determining sub-module may include:
the error operation unit is used for carrying out error operation on the constraint multiplier after the secondary updating to obtain an error parameter;
and the judging unit is used for judging whether the error parameter is within a preset error range, and if so, the constraint multiplier after the secondary updating meets a preset error condition.
Optionally, the error operation unit may be specifically configured to:
performing an error operation on the twice updated constraint multiplier using the following equation:
ey(yK+1,β)=yK+1-Py[yK+1-β(g(yK+1)-ZK+1)],
wherein e is
y(y
K+1Beta) an error parameter, x a foreground matrix, y a background matrix, Z a constraint multiplier, K an iteration number, beta an equalization parameter,
P
y[y
K+1-β(g(y
K+1)-Z
K+1)]representing the projection from the domain to y.
Therefore, in the process of carrying out iterative processing on the matrix model, the constraint multiplier is updated twice in each iteration, so that the updating speed of the constraint multiplier is increased; the faster the update speed of the constraint multiplier is, the faster the convergence speed of the iterative algorithm is; therefore, the application of the scheme has the advantages of high speed of the iterative process and short time consumption.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flow chart of a moving object extraction method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a moving object extraction device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to solve the above technical problem, embodiments of the present invention provide a moving object extraction method and apparatus. The method and the device can be applied to various electronic devices, and are not limited specifically.
Fig. 1 is a schematic flow chart of a moving object extraction method provided in an embodiment of the present invention, including:
s101: and determining a matrix model corresponding to the image by using an analysis algorithm.
As an embodiment, the RPCA algorithm may be used to determine a matrix model corresponding to an image, and specifically, the matrix model may be as shown in equation 1:
wherein the content of the first and second substances,
representing norm, | |
*The method comprises the steps of representing a nuclear norm, representing an iteration step parameter, wherein gamma can be any regularization parameter larger than 0, representing an original matrix corresponding to an image, representing a foreground matrix by x and representing a background matrix by y. In addition, the foreground matrix may also be referred to as a sparse matrix, and the background matrix may also be referred to as a low rank matrix.
Alternatively, other analysis algorithms may be used to determine the matrix model corresponding to the image, which is not limited specifically.
S102: performing iterative processing on the matrix model, wherein each iterative process comprises the following steps: s1021, S1022, S1023, S1024, S1025, and S1026.
S1021: and determining a foreground matrix, a constraint multiplier and a background matrix which are currently corresponding to the matrix model.
It can be understood that, if iteration is performed for the first time, the "foreground matrix, constraint multiplier, and background matrix corresponding to the current time" is the initial value of the foreground matrix, constraint multiplier, and background matrix, and the initial value may be set according to the actual situation; if iteration is not performed for the first time, the current corresponding foreground matrix, constraint multiplier and background matrix are the foreground matrix, constraint multiplier and background matrix determined in the previous iteration process.
S1022: and updating the foreground matrix according to the foreground matrix, the constraint multiplier and the background matrix.
As an embodiment, the foreground matrix x may be updated by using equation 2:
wherein x represents the foreground matrix, y represents the background matrix, Z represents the constraint multiplier, K represents the number of iterations, RM*NRepresenting the domain of definition and L representing the lagrangian function.
S1023: and updating the constraint multiplier once according to the updated foreground matrix, the constraint multiplier and the background matrix.
As an embodiment, the constraint multiplier Z may be updated once using equation 3:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
and Z after one update is shown, gamma represents an iteration step parameter, and beta represents an equalization parameter.
In addition, x is
K+1The foreground matrix after the K +1 th iteration is represented, that is, the foreground matrix after being updated in S1022. In addition, in the scheme, Z is updated twice by one iteration, so that Z after one update is represented as
Z after the second update is represented as Z
K+1。
γ in equation 3 has the same physical meaning as γ in equation 1, and may represent an iteration step parameter. In the updating process of the constraint multiplier Z, an iteration step parameter gamma is introduced, the step length of each iteration can be adjusted, the situations that the iteration times are too many due to too small iteration step length and the optimal value is missed due to too large iteration step length are avoided, and the accuracy of the iteration result is improved.
S1024: and updating the background matrix according to the updated foreground matrix, the constraint multiplier after the primary update and the background matrix.
As an embodiment, the background matrix y may be updated by using equation 4:
wherein x represents the foreground matrix, y represents the background matrix, and Z representsConstraint multiplier, K denotes the number of iterations, ZK+1/2Representing the constraint multiplier, R, after an updateM*NRepresenting the domain of definition and L representing the lagrangian function. In addition, x isK+1Represents the foreground matrix after the K +1 th iteration, that is, the foreground matrix after being updated by S1022, ZK+1/2Represents the constraint multiplier after one update, i.e. Z after S1023 update.
S1025: and updating the constraint multiplier for the second time according to the updated foreground matrix and background matrix and the once updated constraint multiplier.
As an embodiment, the constraint multiplier Z may be updated twice using equation 5:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
represents Z, Z after one update
K+1And Z after the second updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter.
In addition, x is
K+1Represents the foreground matrix after the K +1 th iteration, that is, the foreground matrix y updated in S1022
K+1The background matrix after the K +1 th iteration is represented, that is, the background matrix after being updated by S1024. In addition, in the scheme, Z is updated twice by one iteration, so that Z after one update is represented as
Z after the second update is represented as Z
K+1。
γ in equation 3 has the same physical meaning as γ in equation 1, and may represent an iteration step parameter. In the updating process of the constraint multiplier Z, an iteration step parameter gamma is introduced, the step length of each iteration can be adjusted, the situations that the iteration times are too many due to too small iteration step length and the optimal value is missed due to too large iteration step length are avoided, and the accuracy of the iteration result is improved.
S1026: judging whether the constraint multiplier after the secondary updating meets a preset error condition: if not, performing the next iteration process, namely re-performing S1021-S1026; if yes, the iteration process is finished, that is, S102 is finished, and S103 is executed.
As an embodiment, the determining whether the constraint multiplier after the second updating satisfies the preset error condition may include:
carrying out error operation on the constraint multiplier after the secondary updating to obtain an error parameter;
and judging whether the error parameter is within a preset error range, if so, indicating that the constraint multiplier after the secondary updating meets a preset error condition.
Specifically, the error operation may be performed on the constraint multiplier after the second update by using equation 6:
ey(yK+1,β)=yK+1-Py[yK+1-β(g(yK+1)-ZK+1)],
wherein e is
y(y
K+1Beta) an error parameter, x a foreground matrix, y a background matrix, Z a constraint multiplier, K an iteration number, beta an equalization parameter,
P
y[y
K+1-β(g(y
K+1)-Z
K+1)]representing the projection from the domain to y. The domain may be represented as R
nR represents a real number, and n represents an n-dimensional space.
In addition, y isK+1Represents the background matrix after the K +1 th iteration, that is, the background matrix after the S1024 update, ZK+1The constraint multiplier after the K +1 th iteration is represented, that is, the constraint multiplier after two updates through S1023 and S1025.
Equation 6 can be understood as a shutdown criterion, the error parameter is calculated according to equation 6 after each iteration, and when the error parameter is within a preset error range, the iteration is finished, so that an unnecessary iteration process can be avoided, the iteration times are further reduced, and the iteration time is shortened.
S103: and extracting a moving target in the image according to an iteration result, wherein the moving target corresponds to a foreground matrix in the iteration result.
As will be understood by those skilled in the art, the iterative process is a process of solving for the matrix model determined in S101, and the iterative result is a solution of the matrix model, that is, the foreground matrix x and the background matrix y are calculated. The foreground matrix x is a matrix corresponding to the moving target, and the moving target is extracted by extracting the foreground matrix x.
In the prior art, ADM is used for iterative solution, and the constraint multiplier Z is updated only once during each iteration. The iterative scheme provided in this embodiment may be referred to as SADM (symmetric alternating direction method), and the SADM is used to perform iterative solution, where each iteration updates the constraint Z twice. Those skilled in the art will appreciate that the faster the update speed of the constraint multiplier, the faster the convergence speed of the iterative algorithm.
In addition, in each iteration process, when solving equations 2 and 4, that is, when updating x and y, a Singular Value Decomposition (SVD) algorithm is usually combined:
for example, solving equation 2, the explicit solution of x is:
wherein, UK+1∈Rm×r,VK+1∈Rn×rIn combination with the formula:
Similarly, solving equation 4, the explicit solution of y is:
wherein, UK+1∈Rm×r,VK+1∈Rn×rIn combination with the formula:
Therefore, the SVD algorithm is required to be used for operation at least twice in each iteration process, the calculation amount of the SVD algorithm is large, the SADM applying the scheme is used for iterative solution, and the constraint multiplier Z is updated twice in each iteration, so that the iteration times are reduced, namely the times of operation by using the SVD algorithm are reduced, and the time consumption of the iteration process is further shortened.
By applying the embodiment shown in FIG. 1 of the invention, in the process of carrying out iterative processing on a matrix model, the constraint multiplier is updated twice in each iteration, so that the updating speed of the constraint multiplier is improved; the faster the update speed of the constraint multiplier is, the faster the convergence speed of the iterative algorithm is; therefore, the application of the scheme has the advantages of high speed of the iterative process and short time consumption; in addition, in the scheme, because the iteration is performed once, the constraint multiplier is updated twice, and the iteration times are reduced, the times of applying the SVD algorithm are reduced, and the time consumption of the iteration process is further shortened.
Corresponding to the method embodiment, the embodiment of the invention also provides a moving object extraction device.
Fig. 2 is a schematic structural diagram of a moving object extraction apparatus according to an embodiment of the present invention, including: a determination module 201, an iteration module 202 and an extraction module 203, wherein,
a determining module 201, configured to determine a matrix model corresponding to the image by using an analysis algorithm;
an iteration module 202, comprising: a determination submodule 2021, a first update submodule 2022, a second update submodule 2023, a third update submodule 2024, a fourth update submodule 2025 and a judgment submodule 2026; wherein the content of the first and second substances,
the determining submodule 2021 is configured to determine a foreground matrix, a constraint multiplier, and a background matrix that currently correspond to the matrix model;
the first updating submodule 2022 is configured to update the foreground matrix according to the foreground matrix, the constraint multiplier, and the background matrix;
the second updating submodule 2023 is configured to update the constraint multiplier once according to the updated foreground matrix, the constraint multiplier, and the background matrix;
a third updating sub-module 2024, configured to update the background matrix according to the updated foreground matrix, the constraint multiplier after the first update, and the background matrix;
the fourth updating submodule 2025 is configured to perform secondary updating on the constraint multiplier according to the updated foreground matrix and background matrix and the once updated constraint multiplier;
the judgment sub-module 2026 is configured to judge whether the constraint multiplier after the secondary update meets a preset error condition, if not, trigger the determination sub-module 2021, and if so, trigger the extraction module 203;
and the extracting module 203 is configured to extract a moving object in the image according to an iteration result, where the moving object corresponds to a foreground matrix in the iteration result.
In this embodiment, the first update sub-module 2022 may specifically be configured to:
updating the foreground matrix using the following equation:
wherein x represents the foreground matrix, y represents the background matrix, Z represents the constraint multiplier, K represents the number of iterations, RM*NRepresenting a domain, L representing a Lagrangian function;
the third update sub-module 2024 may be specifically configured to:
updating the background matrix using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, Z represents a constraint multiplier, K represents an iteration number, and Z represents a number of iterationsK+1/2Representing the constraint multiplier, R, after an updateM*NRepresenting the domain of definition and L representing the lagrangian function.
In this embodiment, the second updating sub-module 2023 is specifically configured to:
updating the constraint multiplier once using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
z after one-time updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter;
the second update sub-module 2025 is specifically configured to:
updating the constraint multiplier twice using the following equation:
wherein x represents a foreground matrix, y represents a background matrix, C represents an original matrix corresponding to the image, Z represents a constraint multiplier, K represents the number of iterations,
represents Z, Z after one update
K+1And Z after the second updating is represented, gamma represents an iteration step parameter, and beta represents an equalization parameter.
In this embodiment, the determining sub-module 2026 may include: an error operation unit and a judgment unit (not shown in the figure), wherein,
the error operation unit is used for carrying out error operation on the constraint multiplier after the secondary updating to obtain an error parameter;
and the judging unit is used for judging whether the error parameter is within a preset error range, and if so, the constraint multiplier after the secondary updating meets a preset error condition.
In this embodiment, the error operation unit may be specifically configured to:
performing an error operation on the twice updated constraint multiplier using the following equation:
ey(yK+1,β)=yK+1-Py[yK+1-β(g(yK+1)-ZK+1)],
wherein e is
y(y
K+1Beta) an error parameter, x a foreground matrix, y a background matrix, Z a constraint multiplier, K an iteration number, beta an equalization parameter,
P
y[y
K+1-β(g(y
K+1)-Z
K+1)]representing the projection from the domain to y.
By applying the embodiment shown in FIG. 2 of the invention, in the process of carrying out iterative processing on the matrix model, the constraint multiplier is updated twice in each iteration, so that the updating speed of the constraint multiplier is improved; the faster the update speed of the constraint multiplier is, the faster the convergence speed of the iterative algorithm is; therefore, the application of the scheme has the advantages of high speed of the iterative process and short time consumption; in addition, in the scheme, because the iteration is performed once, the constraint multiplier is updated twice, and the iteration times are reduced, the times of applying the SVD algorithm are reduced, and the time consumption of the iteration process is further shortened.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Those skilled in the art will appreciate that all or part of the steps in the above method embodiments may be implemented by a program to instruct relevant hardware to perform the steps, and the program may be stored in a computer-readable storage medium, which is referred to herein as a storage medium, such as: ROM/RAM, magnetic disk, optical disk, etc.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.