int main() { int c, d; while ((c = getchar()) != EOF) { if (iskanji(c)) { d = getchar(); if (iskanji2(d)) { jis(&c, &d); putchar(c | 0x80); putchar(d | 0x80); } else { putchar(c); if (d != EOF) putchar(d); } } else putchar(c); } return EXIT_SUCCESS; }
void nonMaximaSuppression(const Mat& src, const int sz, Mat& dst, const Mat mask) { // initialise the block mask and destination const int M = src.rows; const int N = src.cols; const bool masked = !mask.empty(); Mat block = 255*Mat_<uint8_t>::ones(Size(2*sz+1,2*sz+1)); dst = Mat_<uint8_t>::zeros(src.size()); // iterate over image blocks for (int m = 0; m < M; m+=sz+1) { for (int n = 0; n < N; n+=sz+1) { Point ijmax; double vcmax, vnmax; // get the maximal candidate within the block Range ic(m, min(m+sz+1,M)); Range jc(n, min(n+sz+1,N)); minMaxLoc(src(ic,jc), NULL, &vcmax, NULL, &ijmax, masked ? mask(ic,jc) : noArray()); Point cc = ijmax + Point(jc.start,ic.start); // search the neighbours centered around the candidate for the true maxima Range in(max(cc.y-sz,0), min(cc.y+sz+1,M)); Range jn(max(cc.x-sz,0), min(cc.x+sz+1,N)); // mask out the block whose maxima we already know Mat_<uint8_t> blockmask; block(Range(0,in.size()), Range(0,jn.size())).copyTo(blockmask); Range iis(ic.start-in.start, min(ic.start-in.start+sz+1, in.size())); Range jis(jc.start-jn.start, min(jc.start-jn.start+sz+1, jn.size())); blockmask(iis, jis) = Mat_<uint8_t>::zeros(Size(jis.size(),iis.size())); minMaxLoc(src(in,jn), NULL, &vnmax, NULL, &ijmax, masked ? mask(in,jn).mul(blockmask) : blockmask); Point cn = ijmax + Point(jn.start, in.start); // if the block centre is also the neighbour centre, then it's a local maxima if (vcmax > vnmax) { dst.at<uint8_t>(cc.y, cc.x) = src.at<uint8_t>(cc.y, cc.x); } } } }