2.3k views
2 votes
Write a function u= CentralMoments (f,n), which returns the mean value and the central moments of the input gray-scale image f in the n-dim array u. u(1) should be the estimated mean value of the image E[X], also called μ. For i = 2,...,n, u(i) should be the estimated ith central moment. Thus u(2) should be the estimated variance E[(X - μ)2], and so on.

Now consider the image rose1024. tif. Use the function intScaling4e that you wrote in your first Lab assignment to put the image into standard form in an array called standard-rose. Check that intensities of standard-rose now lie in the range [0, 1]. Now use the function u= CentralMoments (f,n) to calculate the moments for n = 4 for standard-rose.
Finally transform standard-rose to obtain the image transf-standard-rose so that its mean is exactly 0.5 and the variance is a quarter of the variance of standard-ros You can do this by transforming the intensity of each pixel according to the formula y = ax + b, where y is the transformed intensity and x is the original intensity of a pixel in standard-rose.
Submit, the computed moments, the values of a and b and the images standard-rose and transf-standard-rose. Comment on the relationship between the images and their moments.
Below is my inScaking4e function
function g = intScaling4e(f)
fmin = min(f(:));
fmax = max(f(:));
if isa(f, 'uint8') == 1
g = double(f)/255;
elseif isa(f, 'double') || isa(f, 'single')
if fmin >=0 && fmax<=1
g = f;
else
g = (f - fmin)/(fmax - fmin);
end
else
g = (f - fmin)/(fmax - fmin);
end
end

User Nakeema
by
8.2k points

1 Answer

1 vote

Final answer:

The function CentralMoments(f,n) calculates the mean and central moments of an image. The moments are utilized to scale and transform the image intensities to desired statistical properties, which can alter the image's visual appearance in terms of brightness and contrast.

Step-by-step explanation:

The function CentralMoments(f,n) computes the mean value and the central moments up to the nth moment for a given grayscale image f. The first element of the output array u will contain the estimated mean value of the image, denoted as E[X] or μ. Subsequent elements u(2) to u(n) will contain higher-order central moments, such as the variance for u(2), which represents how spread out the intensity values are from the mean.

In application to the standard-rose image, initially, the intScaling4e function is applied to scale the image intensities to the [0, 1] range. After that, by using CentralMoments(f,n) with n=4, the first four moments are calculated. To transform the standard-rose to have a mean of 0.5 and a variance a quarter of its original variance, the transformation parameters a and b are determined based on the newly computed moments. These values adjust the intensity levels accordingly using the transformation y = ax + b.

The relationship between an image and its moments is crucial as moments capture key statistical properties of the image, such as the average brightness (mean) and the contrast (variance). By transforming the image to adjust these moments, the visual appearance of the image can be significantly altered in terms of its brightness and contrast, which can be observed in the images standard-rose and transf-standard-rose.

User Remon Shehatta
by
7.8k points