简体   繁体   English

添加一维浮点数组值

[英]Adding single dimension float array values

I have two questions regarding the Evil Dicom library. 关于Evil Dicom库,我有两个问题。

I know with the floats function, all of the pixel data is contained as float elements in a one dimensional array. 我知道使用floats函数,所有像素数据都作为一维数组中的float元素包含。 My question here is how can I add up the individual elements to get one value? 我的问题是如何将各个元素加起来以获得一个值?

After I have multiplied a black and white mask with the original image, how can I then add up the non-zero values in the image? 将黑白蒙版与原始图像相乘后,如何将图像中的非零值相加? Do I also use the floats function to get the data as an array and then add up the array elements? 我是否还使用floats函数将数据作为数组获取,然后将数组元素相加? If not, how can I add up the pixels in the image from top left corner to bottom right corner? 如果没有,如何将图像中的像素从左上角添加到右下角?

As far as I know there is no special functionality in the Evil DICOM library for these operations, but there is always LINQ. 据我所知,Evil DICOM库中没有用于这些操作的特殊功能,但始终有LINQ。

If you are looking for the sum of all pixel elements: 如果要查找所有像素元素的总和:

var imgMtx = new ImageMatrix("image.dcm");
var sum = imgMtx.Image.Sum();

If you are looking for the sum of the non-zero values: 如果要查找非零值的总和:

var nonZeroSum = imgMtx.Image.Where(val => val != 0.0f).Sum();

If you are looking for the average value, simply replace Sum with Average . 如果您正在寻找平均值,只需将Sum替换为Average

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM