Fast mean fuzzy algorithm and mean Fuzzy Algorithm

Source: Internet
Author: User
Tags vmin

Fast mean fuzzy algorithm and mean Fuzzy Algorithm

I saw a fast mean fuzzy algorithm on the internet some time ago, with good performance.

Source blog:

Http://www.lellansin.com/super-fast-blur-%E6%A8%A1%E7%B3%8A%E7% AE %97%E6%B3%95.html

The blogger corrected the bug and optimized its performance.

The algorithm is used on the VM to blur a x image, which takes-milliseconds and is very fast.

The Code is as follows:

/** Super Fast Blur v1.1+* Original author: Mario Klingemann (C++ version)* Original address: http://incubator.quasimondo.com/processing/superfastblur.pde* C version updated by Lellansin (http://www.lellansin.com)* C version bugfix and performance optimization by tntmonks (http://tntmonks.cnblogs.com)*/void superFastBlur(unsigned char *pix, unsigned int w, unsigned int h, unsigned int comp, int radius){unsigned int div;unsigned int wm, hm, wh;unsigned int *vMIN, *vMAX;unsigned char *r, *g, *b, *dv;unsigned int rsum, gsum, bsum;unsigned int p, p1, p2, yi, yw;int x, y, i, yp;if (radius < 1)return;wm = w - 1;hm = h - 1;wh = w * h;div = radius + radius + 1;vMIN = (unsigned int *)malloc(sizeof(unsigned int) * max(w, h));vMAX = (unsigned int *)malloc(sizeof(unsigned int) * max(w, h));r = (unsigned char *)malloc(sizeof(unsigned char) * wh);g = (unsigned char *)malloc(sizeof(unsigned char) * wh);b = (unsigned char *)malloc(sizeof(unsigned char) * wh);dv = (unsigned char *)malloc(sizeof(unsigned char) * 256 * div);for (i = 0; i < 256 * div; i++)dv[i] = (i / div);yw = yi = 0;for (y = 0; y < h; y++){rsum = gsum = bsum = 0;for (i = -radius; i <= radius; i++){p = (yi + min(wm, max(i, 0))) * comp;bsum += pix[p];gsum += pix[p + 1];rsum += pix[p + 2];}for (x = 0; x < w; x++){r[yi] = dv[rsum];g[yi] = dv[gsum];b[yi] = dv[bsum];if (y == 0){vMIN[x] = min(x + radius + 1, wm);vMAX[x] = max(x - radius, 0);}p1 = (yw + vMIN[x]) * comp;p2 = (yw + vMAX[x]) * comp;bsum += pix[p1] - pix[p2];gsum += pix[p1 + 1] - pix[p2 + 1];rsum += pix[p1 + 2] - pix[p2 + 2];yi++;}yw += w;}for (x = 0; x < w; x++){rsum = gsum = bsum = 0;yp = -radius * w;for (i = -radius; i <= radius; i++){yi = max(0, yp) + x;rsum += r[yi];gsum += g[yi];bsum += b[yi];yp += w;}yi = x;for (y = 0; y < h; y++){ pix[yi * comp] = (dv[bsum]);pix[yi * comp + 1] = (dv[gsum]);pix[yi * comp + 2] = (dv[rsum]);if (x == 0){vMIN[y] = min(y + radius + 1, hm) * w;vMAX[y] = max(y - radius, 0) * w;}p1 = x + vMIN[y];p2 = x + vMAX[y];rsum += r[p1] - r[p2];gsum += g[p1] - g[p2];bsum += b[p1] - b[p2];yi += w;}} free(r); free(g); free(b); free(vMIN); free(vMAX); free(dv);}

This algorithm can be simply modified for image enhancement.

The algorithm can be further optimized, and this task will be handed over to the audience.

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.