benchmarks comparing the rust image processing ecosystem
opencv resize
bendn 2023-11-07
parent 52ec309 · commit d0d075e
-rw-r--r--benches/resizing.rs57
-rw-r--r--resizing.svg2
2 files changed, 52 insertions, 7 deletions
diff --git a/benches/resizing.rs b/benches/resizing.rs
index fb679ee..18ad709 100644
--- a/benches/resizing.rs
+++ b/benches/resizing.rs
@@ -1,7 +1,46 @@
+#![feature(array_chunks)]
use fimg::Image;
+use opencv::{core::CV_8UC3, prelude::*};
+
const SIZE: u32 = 5424;
const TO: u32 = 2712;
+macro_rules! scale_opencv {
+ ($name:ident => { scale($alg:literal) }) => {
+ fn $name() {
+ opencv::core::set_num_threads(1).unwrap();
+ let mut data = iai::black_box(include_bytes!("../data.imgbuf").to_vec())
+ .array_chunks::<3>()
+ .flat_map(|&[r, g, b]| [b, g, r])
+ .collect::<Vec<_>>();
+ let mut o = unsafe { Mat::new_rows_cols(SIZE as i32, SIZE as i32, CV_8UC3).unwrap() };
+ opencv::imgproc::resize(
+ &unsafe {
+ Mat::new_size_with_data_def(
+ opencv::core::Size_ {
+ width: SIZE as i32,
+ height: SIZE as i32,
+ },
+ CV_8UC3,
+ data.as_mut_ptr() as *mut core::ffi::c_void,
+ )
+ .unwrap()
+ },
+ &mut o,
+ opencv::core::Size_ {
+ width: TO as i32,
+ height: TO as i32,
+ },
+ 0.0,
+ 0.0,
+ $alg,
+ )
+ .unwrap();
+ iai::black_box(&o);
+ }
+ };
+}
+
macro_rules! scale_fimg {
($name:ident => { scale($alg: ident) }) => {
fn $name() {
@@ -56,20 +95,26 @@ macro_rules! scale_img {
scale_fimg!(nearest_fimg => { scale(Nearest) });
scale_img!(nearest_img => { scale(Nearest) });
+scale_opencv!(nearest_opencv => { scale(6) });
scale_fimg!(lanczos_fimg => { scale(Lanczos3) });
scale_img!(lanczos_img => { scale(Lanczos3) });
+scale_opencv!(lanczos_opencv => { scale(4) });
scale_resize!(lanczos_resize => { scale(Lanczos3 )});
-scale_fimg!(catmull_fimg => { scale(CatmullRom) });
-scale_img!(catmull_img => { scale(CatmullRom) });
-scale_resize!(catmull_resize => { scale(Catrom) });
+scale_fimg!(bicubic_fimg => { scale(CatmullRom) });
+scale_img!(bicubic_img => { scale(CatmullRom) });
+scale_resize!(bicubic_resize => { scale(Catrom) });
+scale_opencv!(bicubic_opencv => { scale(2) });
iai::main!(
nearest_fimg,
nearest_img,
+ nearest_opencv,
lanczos_fimg,
lanczos_img,
lanczos_resize,
- catmull_fimg,
- catmull_img,
- catmull_resize
+ lanczos_opencv,
+ bicubic_fimg,
+ bicubic_img,
+ bicubic_resize,
+ bicubic_opencv
);
diff --git a/resizing.svg b/resizing.svg
index bdc6b27..faa65ea 100644
--- a/resizing.svg
+++ b/resizing.svg
@@ -1 +1 @@
-<svg xmlns="http://www.w3.org/2000/svg" width="480" height="480"><path fill="#0d1117" d="M0 0h480v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 444h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 444h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 380.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 380.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 384.4)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 317h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 317h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 320.9)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 253.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 253.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 257.4)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 190.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 190.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 193.91)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 126.51h205.47m126.48 0h8.39" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 126.51h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 130.41)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 63.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 63.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 66.91)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M199.57 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(199.57 465.9)"><tspan>lanczos3</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M284.65 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(284.65 465.9)"><tspan>catmull</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M369.74 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(369.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M388.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M167.66 444h21.28v-55.39h-21.28z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M167.66 444v-55.38h21.27V444h-21.27Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M252.74 444h21.28v-45.11h-21.28z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M252.74 444v-45.1h21.27V444h-21.27Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M337.83 444h21.28v-8.53h-21.28z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M337.83 444v-8.52h21.27V444h-21.27Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M388.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M188.93 444h21.28V88.59h-21.28z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M188.93 444V88.6h21.27V444h-21.27Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M274.01 444h21.29V181.65h-21.29z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M274.01 444V181.66h21.28V444h-21.28Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M359.1 444h21.28v-99.47H359.1z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M359.1 444v-99.46h21.27V444H359.1Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 129.06)"><tspan>resize</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M388.48 129.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 129.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M210.2 444h21.28V203.79H210.2z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M210.2 444V203.8h21.27V444H210.2Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M295.29 444h21.28V270.9h-21.28z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M295.29 444V270.91h21.27V444h-21.27Z"/></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(284.65 32.86)"><tspan>resizing</tspan></text></svg> \ No newline at end of file
+<svg xmlns="http://www.w3.org/2000/svg" width="480" height="480"><path fill="#0d1117" d="M0 0h480v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 444h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 444h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 380.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 380.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 384.4)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 317h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 317h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 320.9)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 253.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 253.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 257.4)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 190.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 190.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 193.91)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 126.51h205.47m126.48 0h8.39" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 126.51h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 130.41)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 63.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 63.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 66.91)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M199.57 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(199.57 465.9)"><tspan>lanczos3</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M284.65 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(284.65 465.9)"><tspan>bicubic</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M369.74 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(369.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M388.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M165.53 444h17.03v-55.4h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M165.53 444v-55.39h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M250.62 444h17.02v-45.11h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M250.62 444v-45.1h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M335.7 444h17.03v-8.53H335.7z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M335.7 444v-8.52h17.02V444H335.7Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M388.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M182.55 444h17.03V88.59h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M182.55 444V88.6h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M267.63 444h17.03V181.64h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M267.63 444V181.65h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M352.72 444h17.03v-99.47h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M352.72 444v-99.46h17.02V444h-17.02Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 129.06)"><tspan>opencv</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M388.48 129.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 129.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M199.57 444h17.02V272.47h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M199.57 444V272.48h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M284.65 444h17.03v-52.33h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M284.65 444v-52.32h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M369.74 444h17.02v-28.35h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M369.74 444v-28.34h17.01V444h-17.01Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 150.06)"><tspan>resize</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M388.48 150.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 150.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M216.58 444h17.03V200.98h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M216.58 444V200.99h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M301.67 444h17.02V269.03h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M301.67 444V269.04h17.01V444h-17.01Z"/></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(284.65 32.86)"><tspan>resizing</tspan></text></svg> \ No newline at end of file