0
$\begingroup$
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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – pmw1234
    May 12 at 18:10
1
$\begingroup$

Yes you can. There are basically two approaches:

  • You draw everything to a framebuffer object. Then you apply image processing fragment shaders to resulting texture of the previous draw call, where the shaders take the pervious texture with a sampler.

or if you have a particular image and you would like to have more control on the numeric precision, the number of neighbours available to you while working on pixel etc:

  • You apply compute shaders directly to image.

For the first approach, see Learn OpenGL, for compute shaders, see Anton's tutorial

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.