%Induce_fog.m % %William Parsons %May 5 2006 % %This program is used to artificially induce fog using the algorithm: % % I(k) = C0(1+(F(k)-1)*exp(-B*R(k)) % %where C0 and B are constants, F represents the image to be fogged, I %represents the fogged image, and R is the distance vector containing the %distance to each pixel. Once the fogged image is produced, the original %and the fogged images are printed. The fogged image is then run through %the algorithm again, this time in reverse, in order to defog it. The %resulting image is also printed. % [y, map] = imread('peppers.jpg'); %convert to grey scale x = rgb2gray(y); %When the image is already grey scale, use this instead: %x = y; %set up constants c0 = 40.0/255.0; B = .0568; %get size of image [M, N] = size(x); %set up distance vector for row = 1:M for col = 1:N R(row, col) = double(row/10.0); %R(row, col) = 40.0 * (1.000 - (double(row)/double(M))^2); end end %convert image to a double x = double(x)/255.0; %fog the image keeping the pixel values between 0 and 1 for row = 1:M for col = 1:N fog(row, col) = (c0 * (1.0 + (((double(x(row, col))) - 1.0) * exp(-B*R(row, col))))); end end %print out original image figure; imshow(uint8(x * 255.0)); %print out fogged image figure; imshow(uint8(fog * 255.0)); %defog the fogged image %for row = 1:M, % for col = 1:N, % test(row, col) = double((exp(B*R(row,col))*fog(row,col))/c0 - exp(B*R(row,col)) + 1.0); % end %end %print the defogged image %figure;imagesc(test);colormap(gray);