Untitled

Anonymous
Plain Text
09/11/2025 6:12 PM
3.5 KB
17
Indexable
Never
template <typename T>
void CBaseMotionDetector::DiffuseVMask(std::vector<T>& dispersion, std::vector<T>& out, int rows, int cols)
{
#ifdef MOTIONDETECTION_LOG_PERFORMANCE
	shared_ptr<ReportDuration>reportDuration(new ReportDuration("Diffuse:"));
#endif
	DBG_NM_PIPE(
		vector<BYTE> dispersion2diffuse;
	dispersion2diffuse.resize(rows * cols * 2);
		)
		int start = -1 * (k_size / 2);
	int end = start + k_size - 1;

	//for testing - insert a high value pixel in middle and test diffusion
	 DBG_NM_PIPE(dispersion[(rows / 2) * cols + (cols / 2)] = 220;)

	for (int r = 0; r < rows; ++r)
	{
		for (int c = 0; c < cols; ++c)
		{
			double srcPixel = dispersion[r * cols + c];

			if (srcPixel < 20)
			{
				//dispersion2diffuse[r * cols + c]
				double v1 = srcPixel;
				double v2 = (double)out[r * cols + c];
				T val = static_cast<T>(std::max(v1, v2));
				out[r * cols + c] = val;

				DBG_NM_PIPE(
					dispersion2diffuse[(r * cols + c) * 2] = static_cast<BYTE>(val);
				dispersion2diffuse[((r * cols + c) * 2) + 1] = YUV_CHROMA_ZERO;
					)
					continue;
			}

			for (int kx = start; kx <= end; ++kx)
			{
				int a = 1;	//dummy statement to bring debugger here
				for (int ky = start; ky <= end; ++ky)
				{
					//check if we are the middle pixel
					if (r == rows / 2 && c == cols / 2)
					{
						int x = 0;
					}
					if (kx == 0 && ky == 0)	//center pixel to be skipped
					{
						T v1 = dispersion[r * cols + c];
						T v2 = out[r * cols + c];
						out[r * cols + c] = std::max(v1, v2);

						DBG_NM_PIPE(
							dispersion2diffuse[(r * cols + c) * 2] = static_cast<BYTE>(out[r * cols + c]);
						dispersion2diffuse[((r * cols + c) * 2) + 1] = YUV_CHROMA_ZERO;
							)
							continue;
					}

					int neighbor_row = r + kx;
					int neighbor_col = c + ky;



					if (neighbor_row >= 0 && neighbor_row < rows && neighbor_col >= 0 && neighbor_col < cols)
					{
						double neighbor_weight = kernel_weights[kx + end][ky + end];
						double diffusion_contrib = srcPixel * neighbor_weight;
						double currPixel = out[neighbor_row * cols + neighbor_col];
						if (currPixel > srcPixel)
							currPixel--;
						T val = static_cast<T>(std::max(currPixel, diffusion_contrib));

						DBG_NM_PIPE(
							dispersion2diffuse[(neighbor_row * cols + neighbor_col) * 2] = static_cast<BYTE>(val);
						dispersion2diffuse[((neighbor_row * cols + neighbor_col) * 2) + 1] = YUV_CHROMA_ZERO;
							)

							out[neighbor_row * cols + neighbor_col] = val;

						DBG_NM_PIPE(
							if (paintEachPixel)
								DiffusedVMaskSender.SendData(dispersion2diffuse);
						)
					}
				}

			}

			DBG_NM_PIPE(
				if (eachKernelPaint)
				{

					DiffusedVMaskSender.SendData(dispersion2diffuse);
				})
		}
	}
	DBG_NM_PIPE(
		DiffusedVMaskSender.SendData(dispersion2diffuse);
	)
}
void CBaseMotionDetector::ThresholdVMask(std::vector<BYTE>& out, std::vector<WORD>& dispersion, const int size)
{

	DBG_NM_PIPE(std::vector<BYTE> outForDebug(dispersion.size() * 2);)		// 2 bytes per pixel
	for (int i = 0; i < dispersion.size(); ++i)
	{
		if (dispersion[i] >= m_NoisePixTh)
		{
			out[i] = YUV_LUMA_MAX; // Y channel
			DBG_NM_PIPE(outForDebug[i * 2] = YUV_LUMA_MAX;) // Y channel
			
		}
		else
		{
			out[i] = YUV_LUMA_MIN; // Y channel
			DBG_NM_PIPE(outForDebug[i * 2] = YUV_LUMA_MIN;) // Y channel
			
		}
		DBG_NM_PIPE(outForDebug[i * 2 + 1] = YUV_CHROMA_ZERO;) // U channel
	}

	DBG_NM_PIPE(thVarianceSender.SendData(outForDebug));
	
}
Editor is loading...
Leave a Comment