# Can I write histogram equalization, blurring, sharpening grayscale image etc.. as shader programs with openGL?

unsigned int histogram[256]={0};
for(int i=0;i<width*height;i++)  //to iterate over pixels
++histogram[image[i]];

const float cutoffpercentage = 0.05;  //To cut off lower and upper values
unsigned char lowerbound,upperbound;
unsigned int histAccu =0;  //pixel entries < 5% =lower bound
const unsigned int lowerpercentile = cutoffpercentage * width*height;
const unsigned int upperpercentile = (1-cutoffpercentage)*width*height;

for(int h =0;h <256;h++){
histAccu += histogram[h];

if(histAccu <= lowerpercentile){
lowerbound = h;
continue;
}

if(histAccu >= upperpercentile){
upperbound = h;
break;
}
}


Then assign new gray values. Can I write this program to equalize the histogram of an image on a gpu shader memory and programs for image segmentation, blurring, sharpening etc...as a shader program using openGL ?? Can we write shader programs just like a normal application program in C ?? Kindly help me on this, as I'm new to shader programming.

• Yes. But it isn't a direct mapping of C code to shader code. Everything you want to do is reasonably straight forward. Going through one of the tutorials for opengl/directx on the web is the best way to get started. That will tell what's involved and how to get everything setup. This site is best for specific questions. Doing a google search for "opengl tutorial" turns up good sites that will get you going. May 12, 2021 at 18:10