Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear ;
- tic;
- input_image=imread('test3.bmp');
- input_image = rgb2gray(input_image);
- %input_image = double(input_image);
- a=uint8(2);
- beta=uint8(2);
- sum1=0;
- cnt = uint8(0);
- difference = uint64(0);
- histogram_of_image = zeros(1,256); %creata an array for histogram
- [width,height] = size(input_image); %width and heigth of image
- figure;
- plot(imhist(input_image));
- title('Original Histogram');
- histogram_of_image = imhist(input_image);
- modified_histogram = zeros(1,256);
- for i=1:256
- modified_histogram(i) = (log( histogram_of_image(i)+double(a)))^double(beta);
- end
- figure('Name','Modified Histogram');
- plot(modified_histogram);
- for i=1:256
- if(modified_histogram(i)~=0)
- sum1 = sum1 + (modified_histogram(i));
- cnt = cnt + 1;
- end
- end
- tcl = sum1/cnt;
- clipped_histogram = zeros(1,256);
- for i=1:256
- if((modified_histogram(i)) >= tcl)
- clipped_histogram(i) = tcl;
- else
- clipped_histogram(i) = (modified_histogram(i));
- end
- end
- figure('Name','Clipped Modified Histogram');
- plot(clipped_histogram);
- PDa = zeros(1,256);
- for i=1:256
- PDa(i) = clipped_histogram(i) / (sum(clipped_histogram));
- end
- CDa = zeros(1,256); %create CDa in formula
- CDa(1) = PDa(1) ;
- for i=2:256
- CDa(i) = PDa(i) + CDa(i-1);
- end
- value_after_enhancement = zeros(1,256);
- for i=1:256
- value_after_enhancement(i) = (255 * CDa(i));
- end
- b=uint8(0);
- output_image=zeros(width,height);
- for i=1:width %map new value
- for j=1:height
- b = input_image(i,j);
- output_image(i,j) = value_after_enhancement(b);
- end
- end
- original_result=imread('testsonuc3.bmp');
- original_result=double(rgb2gray(original_result));
- image_of_dif= zeros(width,height);
- for i=1:width %map new value
- for j=1:height
- d = (output_image(i,j));
- e = (original_result(i,j));
- difference = difference + uint64(abs(d-e));
- piksel_farki=e-d;
- %i has casted to uint64, because type of difference is also uint64
- image_of_dif(i,j)= abs(d-e);
- end
- end
- figure;
- imshow(uint8(output_image));
- title('My Result');
- figure;
- imshow(uint8(original_result));
- title('Original Result');
- figure;
- imshow(uint8(image_of_dif));
- title('Difference of original result and my result');
- toc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement