Exemplo n.º 1
0
std::vector<int> Histogram::getThresh(cv::Mat image, float s1, float s2){
    cv::Mat histMat = BuildHistogram (image);
    std::vector<int> imgThresh;
    imgThresh.push_back(0);
    imgThresh.push_back(255);
    float N = image.rows * image.cols;
    float maxth = (1-s2)*N;
    float minth = s1*N;
    int mini=0,maxi=0;
    float cmini=0,cmaxi=N;
    bool lower=true,higher=true;
    for (int i = 0; i < histMat.rows; i++){
    cmini+= histMat.at<float>(i);
    cmaxi-= histMat.at<float>(256-i);
    if(cmini >= minth && lower==true){
    mini = i;
    lower=false;
    }
    if(cmaxi <= maxth && higher==true){
    maxi = 256-i;
    higher=false;
    }
    if(lower==false && higher ==false )
    break;
    }
    imgThresh[0]=mini;
    imgThresh[1]=maxi;
    return imgThresh;
}
Exemplo n.º 2
0
void SaveXPM( IndexedImg& img, RGBx* palette, char* filename )
{
    // use same chars as gimp
    static const char linenoise [] =
        " .+@#$%&*=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopqrstuvwxyz\
        ABCDEFGHIJKLMNOPQRSTUVWXYZ`";

    XpmImage outimage;
    XpmInfo outinfo = { 0,NULL,NULL,NULL,0,0,0,NULL };

    int hist[256];
    BuildHistogram( img, hist );
    int usedcolors = CountUsedColours( hist );


    outimage.width = img.W();
    outimage.height = img.H();
    outimage.cpp = cpp;
    outimage.ncolors = usedcolours;
    outimage.colorTable = 0;
    outimage.data = stringbuf;
}