Biased std, mstd in dolphindb which are similar to std(ddof=1 or 0) in pandas or numpy - window

Biased std, mstd in dolphindb which are similar to std(ddof=1 or 0) in pandas or numpy
The function std and mstd are used to caculate the standard deviation and the standard deviation in a sliding window. I want to ask is there a parament such like the ddof=1 or 0 in pandas and numpy to caculate the biased standard deviation?

The std function can calculate the standard deviation, and the biased standard deviation can be calculated by the function 'stdp'.
The mstd function can calculate the moving standard deviation in a sliding window with a length of window. The deviation standard deviation can be calculated by the function 'mstdp'.

Related

Algorithms to find difference/similarity in a sequence of images/frames

I am searching for known algorithms (perhaps openCV function) that can output similarity or difference in a given specified number of sequence of images/frames (say 2 or 10).
Journal/conference article is also appreciated. Thank you.
You can perform it using Structural Similarity Index
For related publication check out the paper titled Image Quality Assessment: From Error Visibility to
Structural Similarity by Zou Wang in IEEE TRANSACTIONS ON IMAGE PROCESSING
There isn't any function available in OpenCV (as far as I can remember), though there si one in scikit_image. It is the ssim module made available by this line from skimage.measure import structural_similarity as ssim.
The good thing about ssim is it considers:
the mean of pixel intensities for within a given window.
the variance of the pixel intensities
and the covariance
The formula given in equation 13 of the linked paper contains the above three.
A sample implementation is provided HERE

Does there exist a way to directly figure out the "smoothness" of a digital image?

There exist several ways to evaluate an image, brightness, saturation, hue, intensity, contrast etc. And we always hear about the operation of smoothing or sharperning an image. From this, there must exist a way to evaluate the overall smoothness of an image and an exact way to figure out this value in one formula probably based on wavelet. Or fortunately anyone could even provide the MATLAB function or combination of them to directly calculate this value.
Thanks in advance!
Smoothness is a vague term. What considered smooth for one application might not be considered smooth for another.
In the common case, smoothness is a function of the color gradients. Take a 2d gradient on the 3 color channels, then take their magnitude, sqrt(dx^2 + dy^2) and average, sum or some function over the 3 channels. That can give you local smoothness which you can then sum/average/least squares over the image.
In the more common case, however, linear changes in color is also smooth (think 2 color gradients, or how light might be reflected from an object). For that, a second differential could be more suitable. A laplacian does exactly that.
I've had much luck using the laplacian operator for calculating smoothness in Python with the scipy/numpy libraries. Similar utilities exist for matlab and other tools.
Note that the resulting value isn't something absolute from the math books, you should only use it relative to itself and using constants you deem fit.
Specific how to:
First get scipy. If you are on Linux it's it available on pypi. For Windows you'll have to use a precompiled version here. You should open the image using scipy.ndimage.imread and then use scipy.ndimage.filters.laplace on the image you read. You don't actually have to mix the channels, you can simply call numpy.average and it should be close enough.
import scipy as np
import scipy.ndimage as ndi
print np.average(np.absolute(ndi.filters.laplace(ndi.imread(path).astype(float) / 255.0)))
This would give the average smoothness (for some meaning of smoothness) of the image. I use np.absolute since values can be positive or negative and we don't want them to even out when averaging. I convert to float and divide by 255 to have values between 0.0 and 1.0 instead of 0 to 256, since it's easier to work with.
If you want to see the what the laplacian found, you can use matplotlib:
import matplotlib.pyplot as plt
v = np.absolute(ndi.filters.laplace(ndi.imread(path).astype(float) / 255.0))
v2 = np.average(v, axis=2) # Mixing the channels down
plt.imshow(v2);
plt.figure();
plt.imshow(v2 > 0.05);
plt.show()

What is the base of the logarithm in Log Transformation in image processing?

I am reading gonzales image processing book and as you know the log transformation has been defined like the following in the book:
s = c*log(1+r)
Now I have one question:
Is the logarithm based on 10 or it is a natural logarithm which is based on napier number?
The log transform is used for dark pixels enhancement. The dark pixels in an image are expanded as compare to the higher pixel values. So the base can be any number depending on the visualization effect of image.
I think log10 is often used because it is related to the decibel scale in signal processing, such as what is used in signal to noise definition.
If this is log() from math.h, then it's the natural logarithm.
That is, it's base is e, which is approximately 2.71828.

could numpy.random.poisson be used to add poisson noise to images?

For every pixle of one image,I have its x(int),y(int) and pixel value(float number).
Now I need to add noise to the image.Is numpy.random.poisson appropriate?
I am worried about it because it is not like new pixle value=original value+noise,but like
new pixle value=numpy.random.poisson(original value,1) .And the new values are all integers.
My question is as the title.
My purpose is to get a photometry measurement error for a star.But I have only one iamge.So I do a simulation via adding poisson noise.
Please check the figure got from the ccd image below.The source is the red feature.
This is an old thread, but I know the answer to this, so here goes.
The answer is yes.
imageplusshotnoise = numpy.random.poisson(lam=<noiseless_simulated_image>, size=None)
This will produce a sample image from a Poisson distribution for each pixel of the original image. Poisson distributions have a special property where the mean and the variance are equal. This means that if the mean is say 100 counts that the variance will be 100; hence, the shot noise will have a standard deviation of 10 (variance is equal to the standard deviation squared).
Create a numpy image array with all the values equal to 100
>>> myimage = 100 * np.ones((100,100))
>>> np.mean(myimage)
100.0
>>> np.std(myimage)
0.0
Note that the mean is 100 and the standard deviation is 0 as expected
Now using this image as the lambda of a Poisson distribution will produce a sample from that distribution with the same size
>>> imageplusnoise = np.random.poisson(lam=myimage, size=None)
>>> imageplusnoise.shape
(100, 100)
The mean of the sample will have the same mean as the lambda, but the standard deviation will be equal to the sqrt of the variance, which in a Poisson distribution is equal to the mean.
>>> np.mean(imageplusnoise)
100.0474
>>> np.std(imageplusnoise)
10.015934965843179
To obtain only the shot noise, simple subtract lambda from it and now the mean will be close to zero (if the mean is small, the mean noise will start skewing further from zero), but it will always have the same standard deviation.
>>> noiseonlyimage = imageplusnoise - myimage
>>> np.mean(noiseonlyimage)
0.047399999999999998
>>> np.std(noiseonlyimage)
10.015934965843179
It should be pointed out here that the lam argument is the expectation value of the Poisson distribution and is noiseless. Your starting image looks like it already has noise, so I would start out by modeling the star response through your aperture to obtain the noiseless image say using some point spread function like an airy disk, sinc function or similar as the input to the numpy.random.poisson function.

pixel wise calculation of mean and standard deviation in matlab

I have an image in MATLAB. How can I calculate mean and standard deviation for each pixel?
A one-line answer like your one-line question can be :
mean(TheImage(:))

Resources