
function f=change_slope(original_image, alpha, square, gray, new_file_name)

% This function reads an image, and creates and saves a new image with any
% given alpha (i.e. the slope constant).
% 
% Input:
% original_image - file name of the starting image, give the name as e.g.: ('name.png')
% 
% alpha - the required alpha, as a positive number, 
% (with increasing alpha the new image will be perceived as more blurry)
% 
% square: 0 (if the image is not a square (MxM)) or 1 (if the image is a square) 
% 
% gray: 0 (if image is not in grayscale) or 1 (if the image is in grayscale)
% 
% new_file_name - name of the new image 
% 
% Olga Dyakova, Uppsala University, Motion Vision Group, 2013

image=imread(original_image); %read image
if gray==0
    image=rgb2gray(image);% convert rgb image to grayscale
end
L=min(size(image)); % find the minimum width or height
if square==0
    image=imresize(image, [L L] ,'bicubic'); % resize image to a square
end
fft_image=fftshift(fft2(image)); % perform a Fourier transform and shift the 
                                 % zero-frequency component to the center 
                                 % of the output of the Fourier transformation
abs_im=abs(fft_image); %get an amplitude spectrum image
freq=-L/2:L/2-1; %set the spatial frequencies
[x, y]=meshgrid(freq,freq); % get a full grid of coordinates
[~, ro]=cart2pol(x,y); % transform data to polar coordinates
ro=round(ro);

%% get the average amplitude across all orientations
abs_im_av=zeros(L,L); 
for r=0:L-1
    idx= ro==r;
    temp=mean(abs_im(idx));
    abs_im_av(idx)=temp;
end
%%
zeroslope=fft_image./((abs_im_av)); % create flat amplitude spectrum
filter_image=zeroslope.*(1+ro).^(-alpha); % get the required slope
%% make new image
filter_image_shiftback=ifftshift(filter_image);
image_new=(real(((ifft2(filter_image_shiftback)))));
f=uint8(((image_new-min(image_new(:)))./((max(image_new(:)))-min(image_new(:)))).*255);
%%
figure
imshow(f)
imwrite(f, new_file_name);
end
