简体   繁体   中英

Adding single dimension float array values

I have two questions regarding the Evil Dicom library.

I know with the floats function, all of the pixel data is contained as float elements in a one dimensional array. 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? 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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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