function rms_contr = getrms(image)

% This function calculates the RMS contrast of an image 
%
% Input:
% image: name of a NxM matrix representing an image (any image can be read 
% into this matrix using matlab's function "imread"). The image
% can be rescaled to grayscale with matlab's "rgb2gray" function).
% 
% To filter the image before analysis use either 
% bandpass_imfilt.m or lowpass_imfilt.m
%
% output: rms-contrast, scaled from 0 - 1
% 
% Olga Dyakova, Motion Vision Group, Uppsala University, 2015

[n,m]=size(image);
im_new=double(image)/255;
im_mean=mean2(im_new);
under_sum=(im_new-im_mean).^2;
im_sum=sum(sum(under_sum));
rms_contr=sqrt((1/(n*m))*(im_sum));