实验2.1

#include <bits/stdc++.h>
#define inf 2333333333333333
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)
typedef unsigned char uchar;
//by war
//2020.9.24
using namespace std;
using namespace cv;
int alpha_slider=1;
char TrackbarName[50];
Mat image,new_image;
double alpha,alpha_slider_max=100;
void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

void on_trackbar(int, void*){
    alpha = (double) alpha_slider/(double) alpha_slider_max;
    alpha = -alpha;
    new_image = Mat::zeros(image.size(), image.type());
    For(i,0,image.rows-1)
        For(j,0,image.cols-1)
            For(k,0,2){
                auto x = image.at<Vec3b>(i, j)[k];
                auto temp = (255.0/(1.0+exp(alpha*(x-127.5))));
                new_image.at<Vec3b>(i, j)[k] = saturate_cast<uchar>( temp );
            }
    imshow("Contrast", new_image);
}

signed main(){
    image = imread("/Users/war/Downloads/nk.jpg");
    namedWindow("Contrast", 1);
    sprintf(TrackbarName, "Contrast -> %lf", alpha_slider_max);
    createTrackbar(TrackbarName, "Contrast", &alpha_slider, alpha_slider_max, on_trackbar);
    on_trackbar( alpha_slider, 0 );
    waitKey(0);
    return 0;
}

 

原图:

 

 

 

 

 

 

posted @ 2020-09-24 10:32  WeiAR  阅读(111)  评论(0编辑  收藏  举报