Fastest 3x3 mid-value blur

Source: Internet
Author: User

10.1 After the national day, well-known bloggers: LAVIEWPBT http://www.cnblogs.com/Imageshop/

Launched a small activity that optimizes the ambiguity of the middle value of a 3x3.

I also participate in, today Bo Master LAVIEWPBT shared a good clahe code.

Free spirit, really for its praise.

So I also share this fastest 3x3 median fuzzy code.

Written by: LAVIEWPBT, written in: 2015.10.16, contact qq:33184777///<summary>///Fast Implementation of the 3*3 size of the median blur, the edge 1 pixels is not processed. (2015.10.12 Day)///</summary>///<param name= "SRC" > Raw data. </param>///<param name= "Dest" > Target data.    </param>///Baidu: Fast median search_ an ANSI C implementation.html///optimized version: Fall Feather of the shame contact qq:200759103static unsigned int* Pixgreater = null;static unsigned int* pixless = null;static unsigned int cmptable[256 * * 2] = {0};class aut Ocmptable{public:autocmptable () {unsigned int x, y, p;unsigned int tablelength = "256;pixgreater" = Cmptable;pixles s = cmptable + tablelength;for (x = 0; x < N, + +) {for (y = 0; y < n; y++) {p = x + y * 256;if (x > Y) {pixle SS[P] = x;pixgreater[p] = y;} ELSE{PIXGREATER[P] = x;pixless[p] = y;}}}}; Static autocmptable Initcmptable;is_ret __stdcall Fastest33medianblur (Tmatrix *src, Tmatrix *Dest) {if (SRC = = NULL | | Dest = = null) return is_ret_err_nullreference;if (Src->data = = NULL | | Dest->data = = NULL) returnIs_ret_err_nullreference;if (src->width! = Dest->width | | Src->height! = Dest->height | | Src->channel! = Dest->channel | | Src->depth! = Dest->depth | | Src->widthstep! = dest->widthstep) return is_ret_err_paramismatch;if (src->depth! = is_depth_8u | | Dest->depth! = is_depth_8u) return Is_ret_err_notsupported;is_ret RET = is_ret_ok;if (!pixgreater&&!pixless ) {return is_ret_err_notsupported;} if (Src->data = = dest->data) {Tmatrix *clone = NULL; ret = Is_clonematrix (SRC, &clone); if (ret! = IS_RET_OK) return Ret; ret = Fastest33medianblur (Clone, Dest); Is_freematrix (&clone); return ret;} unsigned int X, Y, Width = src->width, Height = src->height;unsigned char *linep0, *LINEP1, *LINEP2, *linepd;unsigne d int srcwidthstep = src->widthstep;unsigned int dstwidthstep = dest->widthstep;unsigned int srcChannel = Src->Ch annel;unsigned int dstchannel = dest->channel;unsigned char* srcdata = src->data;unsigned char* DstData = Dest->data;if (Srcchannel = = 1) {unsigned int Gray0, Gray1, Gray2, Gray3, Gray4, Gray5, Gray6, Gray7, Gray8, pos;for (Y = 1; Y < Height-1; y++) {LineP0 = Srcdata + (Y-1) * srcwidthstep + 1; LineP1 = LineP0 + srcwidthstep; LineP2 = LineP1 + srcwidthstep; LINEPD = Dstdata + Y *dstwidthstep + 1;for (X = 1; X < Width-1; X + +) {Gray0 = linep0[x-1]; Gray1 = Linep0[x]; Gray2 = linep0[x + 1]; Gray3 = Linep1[x-1]; Gray4 = Linep1[x]; Gray5 = linep2[x + 1]; Gray6 = Linep2[x-1]; Gray7 = Linep2[x]; Gray8 = linep2[x + 1];/* if (Gray1 > Gray2) Swap (Gray1, Gray2); */pos = Gray1 + Gray2 * 256; Gray2 = Pixless[pos]; Gray1 = pixgreater[pos];/* if (Gray4 > Gray5) Swap (Gray4, Gray5); */pos = Gray4 + Gray5 * 256; Gray5 = Pixless[pos]; Gray4 = pixgreater[pos];/* if (Gray7 > Gray8) Swap (Gray7, Gray8); */pos = Gray7 + Gray8 * 256; Gray8 = Pixless[pos]; Gray7 = pixgreater[pos];/* if (Gray0 > Gray1) Swap (Gray0, Gray1); */pos = Gray0 + Gray1 * 256; Gray1 = Pixless[pos]; Gray0 = pixgreater[pos];/* if (GRay3 > Gray4) Swap (Gray3, Gray4); */pos = Gray3 + Gray4 * 256; Gray4 = Pixless[pos]; Gray3 = pixgreater[pos];/* if (Gray6 > Gray7) Swap (Gray6, Gray7); */pos = Gray6 + Gray7 * 256; Gray7 = Pixless[pos]; Gray6 = pixgreater[pos];/* if (Gray1 > Gray2) Swap (Gray1, Gray2); */pos = Gray1 + Gray2 * 256; Gray2 = Pixless[pos]; Gray1 = pixgreater[pos];/* if (Gray4 > Gray5) Swap (Gray4, Gray5); */pos = Gray4 + Gray5 * 256; Gray5 = Pixless[pos]; Gray4 = pixgreater[pos];/* if (Gray7 > Gray8) Swap (Gray7, Gray8); */pos = Gray7 + Gray8 * 256; Gray8 = Pixless[pos]; Gray7 = pixgreater[pos];/* if (Gray0 > Gray3) Swap (Gray0, Gray3); */pos = Gray0 + Gray3 * 256; Gray3 = Pixless[pos]; Gray0 = pixgreater[pos];/* if (Gray5 > Gray8) Swap (Gray5, Gray8); */pos = Gray5 + Gray8 * 256; Gray8 = Pixless[pos]; Gray5 = pixgreater[pos];/* if (Gray4 > Gray7) Swap (Gray4, Gray7); */pos = Gray4 + Gray7 * 256; Gray7 = Pixless[pos]; Gray4 = pixgreater[pos];/* if (Gray3 > Gray6) Swap (Gray3, Gray6); */pos = Gray3 + Gray6* 256; Gray6 = Pixless[pos]; Gray3 = pixgreater[pos];/* if (Gray1 > Gray4) Swap (Gray1, Gray4); */pos = Gray1 + Gray4 * 256; Gray4 = Pixless[pos]; Gray1 = pixgreater[pos];/* if (Gray2 > Gray5) Swap (Gray2, Gray5); */pos = Gray2 + Gray5 * 256; Gray5 = Pixless[pos]; Gray2 = pixgreater[pos];/* if (Gray4 > Gray7) Swap (Gray4, Gray7); */pos = Gray4 + Gray7 * 256; Gray7 = Pixless[pos]; Gray4 = pixgreater[pos];/* if (Gray4 > Gray2) Swap (Gray4, Gray2); */pos = Gray4 + Gray2 * 256; Gray2 = Pixless[pos]; Gray4 = pixgreater[pos];/* if (Gray6 > Gray4) Swap (Gray6, Gray4); */pos = Gray6 + Gray4 * 256; Gray4 = Pixless[pos]; Gray6 = pixgreater[pos];/* if (Gray4 > Gray2) Swap (Gray4, Gray2); */pos = Gray4 + Gray2 * 256; Gray2 = Pixless[pos]; Gray4 = Pixgreater[pos]; LINEPD[1] = Gray4; linepd++;}} return Ret;}     Else{tmatrix *blue = null, *green = NULL, *red = NULL, *alpha = NULL; Because C variables are not initialized, their values are random values, which can cause errors at the time of release. Is_ret ret = Splitrgba (SRC, &blue, &green, &red, &alpha);= IS_RET_OK) goto Done24; #pragma omp parallel num_threads (3) {#pragma omp sections {#pragma omp section {RET = fastest 33MedianBlur (blue, blue);} #pragma omp section {Ret = Fastest33medianblur (green, green);}   #pragma omp section {Ret = Fastest33medianblur (red, red);} }}ret = Combinergba (Dest, Blue, Green, Red, Alpha);D One24:is_freematrix (&blue); Is_freematrix (&green); is_ Freematrix (&red); Is_freematrix (&alpha); return Ret;} return Ret;}

Reference for quick ordering of short values for Exchange method see: Https://github.com/afniHQ/AFNI/blob/ab8ca253b784ae71401927df88da2bc6e16d07c1/src/cs_qsort_small.h

Fastest 3x3 mid-value blur

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.