Reference to scipy.ndimage.maximum_filter
- Swift4
- Xcode9
- iOS11
- OpenCV:iOS pack v3.3.1
var data : [Double] = [
0.1,0.1,0.1,0.1,0.1
,0.1,0.1,0.1,0.1,0.1
,0.1,0.1,0.5,0.1,0.1
,0.1,0.1,0.1,0.1,0.1
,0.1,0.1,0.1,0.1,0.1
]
let openCV = OpenCVWrapper()
openCV.maximum_filter(
&data,
data_size: Int32(data.count),
data_rows: 5,
mask_size: 3)
print(data)
#import "OpenCVWrapper.h"
-(void) maximum_filter: (double *) data
data_size:(int)data_size
data_rows:(int)data_rows
mask_size:(int)mask_size;
#import <opencv2/opencv.hpp>
#import "OpenCVWrapper.h"
using namespace std;
@implementation OpenCVWrapper
-(void) maximum_filter: (double *) data
data_size:(int)data_size
data_rows:(int)data_rows
mask_size:(int)mask_size
{
std::vector<double> vec(&data[0], data + data_size);
cv::Mat m1(vec);
m1 = m1.reshape(0,data_rows);
cout << "m1 = " << m1 << endl;
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT,
cv::Size(mask_size,mask_size),
cv::Point(-1,-1));
cv::Mat d1;
cv::dilate(m1, d1, kernel);
cout << "d1 = " << d1 << endl;
int size = d1.rows*d1.cols*sizeof(double);
std::memcpy(&data[0],d1.data, size);
// release
vector<double>().swap(vec);
m1.release();
d1.release();
kernel.release();
}
@end
m1 = [0.1, 0.1, 0.1, 0.1, 0.1;
0.1, 0.1, 0.1, 0.1, 0.1;
0.1, 0.1, 0.5, 0.1, 0.1;
0.1, 0.1, 0.1, 0.1, 0.1;
0.1, 0.1, 0.1, 0.1, 0.1]
d1 = [0.1, 0.1, 0.1, 0.1, 0.1;
0.1, 0.5, 0.5, 0.5, 0.1;
0.1, 0.5, 0.5, 0.5, 0.1;
0.1, 0.5, 0.5, 0.5, 0.1;
0.1, 0.1, 0.1, 0.1, 0.1]
## Swift Output
[0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.5, 0.5, 0.5, 0.10000000000000001, 0.10000000000000001, 0.5, 0.5, 0.5, 0.10000000000000001, 0.10000000000000001, 0.5, 0.5, 0.5, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001]