%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. % %Get image to fog [y, map] = imread('Tate sun landscape 4.jpg');%'test2.jpg'); %convert to grey scale x = rgb2gray(y); %set up constants c0 = 200.0; b = .0568; %get size of image [M, N] = size(x); %set up distance vector for row = 1:M for col = 1:N dist(((M+1)-row), (((N+1)-col))) = double(row/10.0); end end %convert image to a double x = double(x); %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))/255.0) - 1.0) * exp(-b*dist(row, col))))); end end %print out original image figure; imagesc(x);colormap(gray); %print out fogged image figure;imagesc(fog);colormap(gray); %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*dist(row,col)) + 1.0); % end %end %print the defogged image %figure;imagesc(test);colormap(gray);