In the matlab code, i apply the discrete cosine transform in an image,after applying the dct, the file size of the dct image is increased from the original file size.Is it true without applying quantization and entropy coding,the file size of the dct image is normally high?
The DCT alone effectively doubles the amount of storage required for an image. 8-bit samples require 16-bits after the DCT.
Related
With some requirement it needs to add mixture noise to image in Matlab. Mixture will have Salt & Pepper Noise varying from 5% to 23% with the fix 5% of Gaussian Noise. I am trying to add said mixture to Image with following code:
I = imread('lena_gray_512.tif');
figure, imshow(I);title('ORIGINAL');
J = imnoise(I,'salt & pepper', 0.23);
figure, imshow(J);title('salty');
K = imnoise(J,'gaussian',0,0.0005);
figure, imshow(K);title('both');
First thing is to verify whether the code will add said required noise to image of 23% Salt& Peeper and 5% Gaussian Noise?
Further, median filter is used to remove the mixed Noise from Image, it works good having PSNR 35. Is there any way to get PSNR around 50 for the same Image with this same mixed Noise?
This question already has answers here:
How to know the size of a variable in MATLAB
(6 answers)
Closed 8 years ago.
I need to know how to enumerate the number of bits in an image (in MATLAB) after applying the DCT algorithm (compressing the image) to an image, I need to see the number of bits of an image after applying the DCT algorithm. Because I am applying it to a 512 x 512 image but I am getting the same number of bit before and after compression was wondering is there any Matlab code which calculates the number of bits for an image.
DCT is transform, not compression. No information is lost after applying it to input signal.
Normaly, algorithms like jpg, after DCT transform applies quantization of DCT coefficients to reduce amount of data. After then quantized coefficients arÄ™ compressed using huffman or other lossless compression algorithm.
So DCT is not able to say how many bits you are going to have after. You should ask huffman.
The DCT algorithm itself does not reduce the size of the image matrix.
It applies a transform to the spatial domain matrix input, and outputs a
matrix in the frequency domain. See this for a more detailed explanation.
http://www.mathworks.com/help/images/discrete-cosine-transform.html#f21-16149
Depending on the number of DCT coefficients discarded, which dictates the amount
of compression you are applying, the remaining non-zero coefficients tells you how
many bits remains. The number of bits per coefficient is determined by the class of
the image X.
e.g.
class(X)
ans =
double
double is 64 bit
single is 32 bit
I'm trying to figure out how MATLAB does the short time Fourier transforms for its spectrogram function (and related functions like specgram, or stft in Octave). What is curious to me is that you can apparently specify the length of the window and the FFT length (number of output frequencies) independently, whereas I would have expected that these two should be equal (since the length of an FFT'd signal is the same as the length of the original signal). To illustrate what I mean, here is the function call:
[S,F,T]=spectrogram(signal,winSize,overlapSize,fftSize,rate);
winSize is the length of subintervals which are to be (individually) FFT'd, and fftSize is the number of frequency components given in the output. When these are not equal, does Matlab do interpolation to produce the required number of frequency bins?
Ultimately the reason I want to know is so that I can determine the proper units and scaling for the frequencies.
Cheers
A windowed segment of a signal can be zero-padded to a longer length vector to use a longer FFT. The frequency scaling will be determined by the length of the FFT (and the signals sample rate). The window size and window formula will determine the effective resolution, in terms of peak separation ability.
Why do this? Some FFT sizes can be computed more efficiently than others (slightly or a lot, depending on the FFT library used). Also, a longer FFT will calculate more points or bins, thus producing a higher density of interpolated points in a potentially smoother spectrum result.
I'm trying to write a simple matlab code which enlarges an image using fft. I tried the known algorithm for image expansion, which computes the Fourier transform of the image, pads it with zeros and computes the inverse Fourier of the padded image.
However, the inverse Fourier transform returns an image which contains complex numbers.
Therefore, when I'm trying to show the result using imshow, I'm getting the following error:
Warning: Displaying real part of complex input.
Do you have an idea what am I doing wrong?
my code:
im = imread('fruit.jpg');
imFFT = fft2(im);
bigger = padarray(imFFT,[10,10]);
imEnlarged = ifft2(bigger);
Thanks!
That's because the FFT returns values corresponding to the discrete (spatial) frequencies from 0 through Fs, where Fs is the (spatial) sampling rate. You need to insert zeros at high frequencies, which are located at the center of the returned FFT, not in its end.
You can use fftshift to shift the high frequencies to the end, pad with zeros, and then shift back with ifftshift (thanks to #Shai for the correction):
bigger = ifftshift(padarray(fftshift(imFFT),[10,10]));
Also, note that padding with zeros decreases the values in the enlarged image. You can correct that using a suitable amplification factor amp, which in this case would be equal to (1+2*10/length(im))^2:
bigger = ifftshift(padarray(fftshift(amp*imFFT),[10,10]));
You can pad at the higher frequencies directly (without fftshift suggested by Luis Mendo)
>> BIG = padarray( amp*imFFT, [20 20], 0, 'post' );
>> big = ifft2( BIG );
If you want a strictly real result, then before you do the IFFT you need to make sure the zero-padded array is exactly conjugate symmetric. Adding the zeros off-center could prevent this required symmetry.
Due to finite numerical precision, you may still end up with a complex IFFT result, but the imaginary components will all be tiny values that are essentially equivalent to zero.
Your FFT library may contain a half-to-real (quarter-size input for 2D) version that enforces symmetry and throws away the almost-zero numerical noise for you.
I am trying to prove that the white noise has constant power spectral density using matlab
but the amplitude of the spectrum looks like random amplitude.
can anyone tell me why?
here is my code.
noise = randn(1,10000);
fft_noise=fft(noise);
plot(abs(fft_noise(1:5000)))
thanks.
You need to average a bunch (law of large numbers) of FFTs of white noise to approach the average power spectral density.
If you take the FFT of an independent set of random variables from the same distribution, then you'll get an independent set of random variables from the same distribution since the inverse Fourier transform is (more or less) the same as the Fourier transform. The point is that the expected value for each frequency is the same.
you need to multiple the fft by the complex conjugate of the fft to show a flat PSD. i.e. change
fft_noise=fft(noise);
to
fft_noise=fft(noise).*conj(fft(noise));