본문 바로가기

Programming

OpenCV How to handle single channel image matrix each pixel, add/subtract/multiply/division (1), 이미지 매트릭스 각 픽셀단위 값 조정하기 (영상처리, image processing) (1)

OpenCV How to handle single channel image matrix each pixel, add/subtract/multiply/division (1)



이미지 매트릭스 각 픽셀단위 값 조정하기 (영상처리, image processing) (1)


Handling each pixel in matrix using put/get in OpenCV



1) / 2) both worked well, but second one did better performance.


I changed to 3) using Core in OpenCV, and i'll post later.



You can use any operator, but example code is about append.



1/2 둘다 동작하고, 두번째 코드가 더 빠르다.


3번째는 Core 사용으로 간략화하고 빠르게 했는데, 나중에 따로 포스팅 예정.


해당 위치에 사칙연산 아무거나 넣어서 쓰면 된다.




Example code




/**

 * All elements' sum (1 channel)

 * @param mat

 * @return

 */

public static float matSum(final Mat mat) {

// 2

float sum = 0;

float[] buffer = new float[(int) mat.total()];

mat.get(0, 0, buffer);

for (float val : buffer)

{

sum += val;                                    // Operator you want here

}

return sum;

// 1

// float sum = 0;

//

// int rows = mat.rows();

// int cols = mat.cols();

//

// for (int i = 0; i < rows; ++i) 

// {

// for (int j = 0; j < cols; ++j) 

// {

// double[] buffer1 = mat.get(i, j);

// sum += buffer1[0];                    // Operator you want here

// }

// }

// return sum;

}




Something else you might like..




2018/11/26 - [Programming/Java] - Arithmetic of complex number(2) division example code, 복소수 사칙연산(2) 나눗셈 코드, real/imaginary, java, opencv, matrix (2)

2018/11/22 - [Programming/Java] - Arithmetic of complex number(1) multiply example code, 복소수 사칙연산(1) 곱셈 코드, real/imaginary, java, opencv, matrix (1)


2018/11/22 - [Programming/Java] - Java foreach statement (advanced for iteration statement) 자바 향상된 for문 문법


2018/11/22 - [Programming/Image Processing] - OpenCv, How to create/initialize mat in CV for Java, 매트릭스 생성/초기화, 자바, c++, JavaCv



2018/11/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #32 absoluteValuesSumMinimization. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/11/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #31 depositProfit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/11/18 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #30 circleOfNumbers. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar



2018/11/17 - [Programming/C++] - How to initialize vector in C++ STL (Standard Template Library), STL 벡터 초기화 방법