@@ -4,7 +4,7 @@ use ndarray::{Array3, ArrayView3};
44#[ cfg( feature = "opencv" ) ]
55use opencv:: {
66 core:: { AlgorithmHint , Mat } ,
7- imgproc:: { cvt_color, resize, COLOR_RGB2GRAY , INTER_LANCZOS4 } ,
7+ imgproc:: { cvt_color, resize, COLOR_RGB2GRAY , INTER_LANCZOS4 , INTER_LINEAR } ,
88 prelude:: * ,
99} ;
1010
@@ -30,6 +30,15 @@ impl OpenCVBatchProcessor {
3030 & self ,
3131 images : & [ ArrayView3 < u8 > ] ,
3232 target_sizes : & [ ( u32 , u32 ) ] , // (width, height)
33+ ) -> Result < Vec < Array3 < u8 > > > {
34+ self . batch_resize_images_with_interpolation ( images, target_sizes, INTER_LINEAR )
35+ }
36+
37+ fn batch_resize_images_with_interpolation (
38+ & self ,
39+ images : & [ ArrayView3 < u8 > ] ,
40+ target_sizes : & [ ( u32 , u32 ) ] , // (width, height)
41+ interpolation : i32 ,
3342 ) -> Result < Vec < Array3 < u8 > > > {
3443 if images. len ( ) != target_sizes. len ( ) {
3544 anyhow:: bail!( "Number of images and target sizes must match" ) ;
@@ -39,7 +48,7 @@ impl OpenCVBatchProcessor {
3948 . iter ( )
4049 . zip ( target_sizes. iter ( ) )
4150 . map ( |( image, & ( target_width, target_height) ) | {
42- self . resize_single_opencv ( image, target_width, target_height)
51+ self . resize_single_opencv ( image, target_width, target_height, interpolation )
4352 } )
4453 . collect :: < Result < Vec < _ > > > ( ) ?;
4554
@@ -111,8 +120,7 @@ impl OpenCVBatchProcessor {
111120 images : & [ ArrayView3 < u8 > ] ,
112121 target_sizes : & [ ( u32 , u32 ) ] , // (width, height)
113122 ) -> Result < Vec < Array3 < u8 > > > {
114- // Use the same implementation as batch_resize_images but with Lanczos4
115- self . batch_resize_images ( images, target_sizes)
123+ self . batch_resize_images_with_interpolation ( images, target_sizes, INTER_LANCZOS4 )
116124 }
117125
118126 /// Single image resize using OpenCV
@@ -121,6 +129,7 @@ impl OpenCVBatchProcessor {
121129 image : & ArrayView3 < u8 > ,
122130 target_width : u32 ,
123131 target_height : u32 ,
132+ interpolation : i32 ,
124133 ) -> Result < Array3 < u8 > > {
125134 let ( _height, _width, channels) = image. dim ( ) ;
126135
@@ -139,7 +148,7 @@ impl OpenCVBatchProcessor {
139148 opencv:: core:: Size :: new ( target_width as i32 , target_height as i32 ) ,
140149 0.0 ,
141150 0.0 ,
142- INTER_LANCZOS4 ,
151+ interpolation ,
143152 ) ?;
144153
145154 // Convert back to ndarray
@@ -243,7 +252,7 @@ pub fn resize_bilinear_opencv(
243252 target_height : u32 ,
244253) -> Result < Array3 < u8 > > {
245254 let processor = OpenCVBatchProcessor :: new ( ) ;
246- processor. resize_single_opencv ( image, target_width, target_height)
255+ processor. resize_single_opencv ( image, target_width, target_height, INTER_LINEAR )
247256}
248257
249258#[ cfg( feature = "opencv" ) ]
@@ -253,7 +262,7 @@ pub fn resize_lanczos4_opencv(
253262 target_height : u32 ,
254263) -> Result < Array3 < u8 > > {
255264 let processor = OpenCVBatchProcessor :: new ( ) ;
256- processor. resize_single_opencv ( image, target_width, target_height)
265+ processor. resize_single_opencv ( image, target_width, target_height, INTER_LANCZOS4 )
257266}
258267
259268#[ cfg( not( feature = "opencv" ) ) ]
0 commit comments