ImageJ marco Alpha-Beta Contrast Stretching.

此代码适用于灰度图

width=getWidth();
height=getHeight();
histo=newArray(256);
for (y=0;y<height;y++){
    for(x=0;x<width;x++){
        v=getPixel(x,y);
        histo[v]++;
    }
}
cumu=newArray(256);
temp=0;
for(i=0;i<256;i++){
    temp+=histo[i];
    cumu[i]=temp;
}

up=width*height*0.9;
down=width*height*0.1;
qup=0;
qdown=0;
for(i=255;i>0;i--)
{
    if (cumu[i]<=up)
        {qup=i;
        break;
        }
}
for (i=0;i<256;i++)
{
    if  (cumu[i]>down){
        qdown=i;
        break;
        }
}
for (y=0;y<height;y++){
    for(x=0;x<width;x++){
        v=getPixel(x,y);
        setPixel(x,y,255/(qup-qdown)*(v-qdown));
    }
}

猜你喜欢

转载自blog.csdn.net/qq_30117591/article/details/89874301