MATLAB's built in function to compute local binary patterns, from the computer vision toolbox, produces real valued numbers.
The function is named: extractLBPFeatures()
I understood the values from LBP to be binary - it's in the name!
What is it doing to get real valued numbers rather than binary values?
According to Matlab documentation, the call extractLBPFeatures(<your_image>) returns a 1-by-59 vector representing the L2-normalized histogram of the non rotation-invariant uniform LBPs, i.e. the relative frequencies of these 59 possible patterns throughout the image. The code of a non rotation-invariant uniform LBP formed by 8 neighbouring pixels is a whole number ranging from 0 to 58, whereas the 59 components of the feature vector yielded by extractLBPFeatures are floating point numbers in the range 0..1.
If you wish to obtain an image where the pixel intensity values are replaced by the LBP codes you could use the Matlab implementation developed by the creators of the LBP descriptor.
Related
I want to do a comparison of 2 audio files (each audio file is speaking "ba a ta") with the existing function in matlab called Dynamic Time Warping (DTW). Before doing a dynamic time warping, I get an array/vector from the Fast Fourier Transform (FFT) functions available in matlab, my code so far (my matlab filename: test.m):
fftRecording1 = fft(audioread('C:\Users\handy\Documents\MATLAB\my_recording_1.wav'));
fftRecording2 = fft(audioread('C:\Users\handy\Documents\MATLAB\fajar.wav'));
dist = dtw(fftRecording1, fftRecording2);
When I try the DTW function there is an error because the length (row) of the array/vector 2 file is different. Error message:
Error using dtw (line 82)
The number of rows between X and Y must be equal when X and Y are matrices
Error in test (line 3)
dist = dtw(fftRecording1, fftRecording2);
contents of the fftRecording1 and fftRecording2 variables
My question is: before do the FFT and DTW, how do step by step normalize so that the length (row) 2 audio files is equal? or there are other ways to make the data length (row) 2 audio files is equal?
According to dtw's documentation:
To stretch the inputs, dtw repeats each element of x and y as many times as necessary. If x and y are matrices, then dist stretches them by repeating their columns. In that case, x and y must have the same number of rows.
In your case your columns represent the audio channels, with the rows representing the quantity to be aligned (i.e. the reverse of what dtw is expecting). To setup the inputs according to what dtw expect, simply transpose the inputs:
dist = dtw(transpose(fftRecording1), transpose(fftRecording2));
Dynamic Time Warping does not need the input sequences to be of same length. DTW is actually used to find similarity between two different time aligned sequences.
No, they don’t need to have the same length in a time-related-sense. They need to have the same number of dimensions (2D Signal, 3D Signal,...) which is equivalent to their number or rows. The whole idea of DTW is to match similar contents which might be stretched to different lengths - so there would absolutely be no point in requiring the inputs to have the same length.
Related to your question: just call the dtw with the transposed of your signals and you will get a proper result.
dtw(signal1’, signal2’);
You should apply the DTW on the original signals rather than the fourier transforms. The FFT transfers the signal from time to frequency domain. So instead of warping signal1 in order to match signal2, you are warping frequencies when using FFT before DTW. The amplitude of the fourier transform depends on the number of points in the considered FFT-Time-Window. From my point of view there is absolutely no point in applying DTW on a fourier transform.
I couldn't find an answer for RGB image.
How can someone get a value of SD,mean and Entropy of RGB image using MATLAB?
From http://airccse.org/journal/ijdms/papers/4612ijdms05.pdf TABLE3, it seems he got one answer so did he get the average of the RGB values?
Really in need of any help.
After reading the paper, because you are dealing with colour images, you have three channels of information to access. This means that you could alter one of the channels for a colour image and it could still affect the information it's trying to portray. The author wasn't very clear on how they were obtaining just a single value to represent the overall mean and standard deviation. Quite frankly, because this paper was published in a no-name journal, I'm not surprised how they managed to get away with it. If this was attempted to be published in more well known journals (IEEE, ACM, etc.), this would probably be rejected outright due to that very ambiguity.
On how I interpret this procedure, averaging all three channels doesn't make sense because you want to capture the differences over all channels. Doing this averaging will smear that information and those differences get lost. Practically speaking, if you averaged all three channels, should one channel change its intensity by 1, and when you averaged the channels together, the reported average would be so small that it probably would not register as a meaningful difference.
In my opinion, what you should perhaps do is treat the entire RGB image as a 1D signal, then perform the mean, standard deviation and entropy of that image. As such, given an RGB image stored in image_rgb, you can unroll the entire image into a 1D array like so:
image_1D = double(image_rgb(:));
The double casting is important because you want to maintain floating point precision when calculating the mean and standard deviation. The images will probably be of an unsigned integer type, and so this casting must be done to maintain floating point precision. If you don't do this, you may have calculations that get saturated or clamped beyond the limits of that data type and you won't get the right answer. As such, you can calculate the mean, standard deviation and entropy like so:
m = mean(image_1D);
s = std(image_1D);
e = entropy(image_1D);
entropy is a function in MATLAB that calculates the entropy of images so you should be fine here. As noted by #CitizenInsane in his answer, entropy unrolls a grayscale image into a 1D vector and applies the Shannon definition of entropy on this 1D vector. In a similar token, you can do the same thing with a RGB image, but we have already unrolled the signal into a 1D vector anyway, and so the input into entropy will certainly be well suited for the unrolled RGB image.
I have no idea how the author actually did it. But what you could do, is to treat the image as a 1D-array of size WxHx3 and then simply calculate the mean and standard deviation.
Don't know if table 3 is obtain in the same way but at least looking at entropy routine in image toolbox of matlab, RGB values are vectorized to single vector:
I = imread('rgb'); % Read RGB values
I = I(:); % Vectorization of RGB values
p = imhist(I); % Histogram
p(p == 0) = []; % remove zero entries in p
p = p ./ numel(I); % normalize p so that sum(p) is one.
E = -sum(p.*log2(p));
I'm looking for available code that can estimate the kernel density of a set of 2D weighted points. So far I found this option in for non-weighted 2D KDE in MATLAB: http://www.mathworks.com/matlabcentral/fileexchange/17204-kernel-density-estimation
However it does not incorporate the weighted feature. Is there any other implemented function or library that should come in handy for this? I thought about "hacking" the problem, where suppose I have simple weight vector: [2 1 3 1], I can literally just repeat each sampled point, twice, once, three times and once respectively. I'm not sure if this computation would be valid mathematically though. Again the issue here is that the weight vector I have is decimal, so normalizing to the minimum number of the vector and then multiplying each other entry implies errors in rounding, specially if the weights are in the same order of magnitude.
Note: The ksdensity function in MATLAB has the weighted option but it is only for 1D data.
Found this, so problem solved. (I guess): http://www.ics.uci.edu/~ihler/code/kde.html
I used this function and found it to be excellent. I discuss varying the n parameter (area over which density is calculated) in this Stack Overflow post, and it contains some examples of 2D KDE plots using contour3.
In Matlab I've got a binomial PDF already defined where the set of possible events are 0-255. I would like to generate symbols, from 0-255, according to that PDF. How can I do that?
This is the code used in order to generate the PDF:
x=0:255; %range of possible values
m=255;
b=0.06245;
y=binopdf(x,m,b); %generates a binomial distribution
When plotting "y" I can see that most of the times the symbol that the source will generate will be between 9 to 23. Again, how can I design that symbol source? Thank you.
Use
result = binornd(m,b,R,C);
to generate an R x C matrix of random values drawn from an (m,b) binomial distribution.
If you then plot the histogram
hist(result(:),-.5:255.5)
you can check that (for R and/or C large enough) the obtained values follow the desired binomial distribution.
According to MATLAB's documentation the $p$-th bin contains the pixels between
$A\frac{(p-1.5)}{n-1}\leq x<A\frac{p-0.5}{n-1}$, where $x$ is the pixel intensity, and $n$ is the number of bins.
As far as I can understand this, $A$ is a scaling factor that is the maximal value of the data type used (e.g. if $A=1$ we consider an image with $x\in[0,1]$).
What I don't really understand, why we use the constants in the expression; for the first bin (assuming that MATLAB considers $p=1$ instead of $p=0$ as the first bin) we put values between $x\in[\frac{-0.5}{(n-1)}, \frac{0.5}{(n-1)}]$, but we have values between $x\in[0,1]$ so the effective width of the bin is only half of the "normal" bins (same goes to the last bin). Why don't MATLAB use $A\frac{p}{n-1}\leq x<A\frac{p+1}{n-1}$ for $p\in[0,n-1]$?
The answer was actually pretty easy and not MATLAB-related: if you divide your domain equidistantly (and choose these values as the representative value of the corresponding quantization level) and pick thresholds at the centroid of each of these intervals endpoints you get the thresholds that MATLAB uses.