Whats the most efficient way to create a 2D array based on a 3D array? I have the following input 3D array, which encodes the rgb information of a picture:
[[[255,255,255], [255,255,255], [255,255,255], ... ]]
i want to create a new 2D array which is a mask essentially, checking if the rgb values yield above a certain threshold:
[[true, false, true, false, ...]]
When i operate on each of the rgb values, I am doing a series of multiplications, additions and sqrts, and the final value of this operation determines the values of the 2D array output, either true or false.
Thanks in advance.
EDIT: I am trying to convert this C++ code to python:
cv::Mat diffImage;
cv::absdiff(backgroundImage, currentImage, diffImage);
cv::Mat foregroundMask = cv::Mat::zeros(diffImage.rows, diffImage.cols, CV_8UC1);
float threshold = 30.0f;
float dist;
for(int j=0; j<diffImage.rows; ++j)
for(int i=0; i<diffImage.cols; ++i)
{
cv::Vec3b pix = diffImage.at<cv::Vec3b>(j,i);
dist = (pix[0]*pix[0] + pix[1]*pix[1] + pix[2]*pix[2]);
dist = sqrt(dist);
if(dist>threshold)
{
foregroundMask.at<unsigned char>(j,i) = 255;
}
}