singe_npp/pipeline/image/
statistics_outputs.rs1use std::marker::PhantomData;
2
3use singe_cuda::memory::DeviceMemory;
4
5use crate::{
6 error::Result,
7 image::view::{C1, ChannelLayout, ImageView, ImageViewMut},
8 types::Size,
9 utility::checked_len,
10};
11
12#[derive(Debug)]
13pub struct ImageStatistic<T> {
14 values: DeviceMemory<T>,
15}
16
17impl<T> ImageStatistic<T> {
18 pub(in crate::pipeline::image) const fn from_values(values: DeviceMemory<T>) -> Self {
19 Self { values }
20 }
21
22 pub const fn len(&self) -> usize {
23 self.values.len()
24 }
25
26 pub const fn is_empty(&self) -> bool {
27 self.values.is_empty()
28 }
29
30 pub fn values(&self) -> &DeviceMemory<T> {
31 &self.values
32 }
33
34 pub fn values_mut(&mut self) -> &mut DeviceMemory<T> {
35 &mut self.values
36 }
37
38 pub fn into_values(self) -> DeviceMemory<T> {
39 self.values
40 }
41}
42
43#[derive(Debug)]
44pub struct ImageHistograms {
45 pub channels: Vec<ImageStatistic<i32>>,
46}
47
48impl ImageHistograms {
49 pub fn len(&self) -> usize {
50 self.channels.len()
51 }
52
53 pub fn is_empty(&self) -> bool {
54 self.channels.is_empty()
55 }
56}
57
58#[derive(Debug)]
59pub struct ImageMeanStandardDeviation<T> {
60 pub mean: ImageStatistic<T>,
61 pub standard_deviation: ImageStatistic<T>,
62}
63
64#[derive(Debug)]
65pub struct ImageMinMax<T> {
66 pub min: ImageStatistic<T>,
67 pub max: ImageStatistic<T>,
68}
69
70#[derive(Debug)]
71pub struct ImageIndexedStatistic<T> {
72 pub value: ImageStatistic<T>,
73 pub index_x: ImageStatistic<i32>,
74 pub index_y: ImageStatistic<i32>,
75}
76
77#[derive(Debug)]
78pub struct ImageIndexedMinMax<T> {
79 pub min: ImageIndexedStatistic<T>,
80 pub max: ImageIndexedStatistic<T>,
81}
82
83#[derive(Debug)]
84pub struct ContiguousImage<T, L = C1> {
85 values: DeviceMemory<T>,
86 size: Size,
87 _marker: PhantomData<L>,
88}
89
90impl<T, L> ContiguousImage<T, L>
91where
92 L: ChannelLayout,
93{
94 pub fn create(size: Size) -> Result<Self> {
95 let len = checked_len(size, L::CHANNELS)?;
96 Ok(Self {
97 values: DeviceMemory::<T>::create(len)?,
98 size,
99 _marker: PhantomData,
100 })
101 }
102
103 pub const fn size(&self) -> Size {
104 self.size
105 }
106
107 pub const fn values(&self) -> &DeviceMemory<T> {
108 &self.values
109 }
110
111 pub fn into_values(self) -> DeviceMemory<T> {
112 self.values
113 }
114
115 pub fn view(&self) -> Result<ImageView<'_, T, L>> {
116 ImageView::from_memory(&self.values, self.size)
117 }
118
119 pub fn view_mut(&mut self) -> Result<ImageViewMut<'_, T, L>> {
120 ImageViewMut::from_memory(&mut self.values, self.size)
121 }
122}
123
124#[derive(Debug)]
125pub struct ImageSquaredIntegral<T, S> {
126 pub integral: ContiguousImage<T, C1>,
127 pub squared: ContiguousImage<S, C1>,
128}