@@ -240,22 +240,22 @@ \subsection{Lossy image coding: JPEG}
240240
241241\paragraph {Step 3.3 } Let's quantize the image's spectral
242242content. First, find the number of zero elements in the FFT, using
243- something like \verb |origZero=length(find(abs(a )==0)); |, where
244- \verb |a | is the FFT. \emph {Remember to exclude the DC value in the
243+ something like \verb |origZero=length(find(abs(origX )==0)); |, where
244+ \verb |origX | is the FFT. \emph {Remember to exclude the DC value in the
245245 \texttt {fft2 } output in figuring out this range. } Then, zero out
246246additional frequency components by zeroing out all with magnitudes
247247below some threshold. You'll want to set the threshold somewhere
248- between the min and max magnitudes of \verb |a |, which you can get as
249- \verb |mn=min(min(abs(a ))); | and \verb |mx=max(max(abs(a ))); |. Let's
248+ between the min and max magnitudes of \verb |origX |, which you can get as
249+ \verb |mn=min(min(abs(origX ))); | and \verb |mx=max(max(abs(origX ))); |. Let's
250250make four tests, with thresholds 5\% , 10\% , 20\% , and 50\% of the way
251251between the min and max, i.e., \verb |th=0.05*(mx-mn)+mn; |. Zero out
252252all FFT values below the threshold using something like:
253253\ begin{lstlisting} [style=Matlab-editor,basicstyle=\mlttfamily\small]
254- b = a ;
255- b (abs(a )<th) = 0; % Uses logical array indexing
254+ compX = origX ;
255+ compX (abs(origX )<th) = 0; % Uses logical array indexing
256256\end {lstlisting }
257257You can count the number of elements thresholded by finding the number
258- of zero elements in \verb |b | at this point and subtracting the number
258+ of zero elements in \verb |compX | at this point and subtracting the number
259259that were originally zero (i.e., \verb |origZero |). This is an estimate
260260of the amount the image could be compressed with an entropy
261261coder. Express the number of thresholded elements as a fraction of the
@@ -270,17 +270,20 @@ \subsection{Lossy image coding: JPEG}
270270you suggest an approach that will take this into account? How does the
271271JPEG algorithm deal with or avoid this problem?
272272
273+ \begin {sloppypar }
273274\paragraph {Step 3.4 } Now we will see the effect of this thresholding
274275on image quality. Convert the thresholded FFT back to an image using
275- something like \verb |c = abs(ifft2(b)); |. For each type of image and
276- each threshold value, plot the original image and the final processed
277- image. Compute the mean squared error (MSE) between the original and
278- reconstructed image (mean squared error for matrices can be computed
279- as \verb |mean(mean((a-c).^2)) |). What can you say about the effects
280- on the image and MSE? Collect your code together as a script to
281- automate the thresholding and reconstruction, so you can easily
282- compute MSE for a number of thresholds. Plot MSE vs. threshold
276+ something like \verb |reconstructed = abs(ifft2(compX)); |. For each
277+ type of image and each threshold value, plot the original image and
278+ the final processed image. Compute the mean squared error (MSE)
279+ between the original and reconstructed image (mean squared error for
280+ matrices can be computed as
281+ \verb |mean(mean((original-reconstructed).^2)) |). What can you say
282+ about the effects on the image and MSE? Collect your code together as
283+ a script to automate the thresholding and reconstruction, so you can
284+ easily compute MSE for a number of thresholds. Plot MSE vs. threshold
283285percentage (just as you plotted fraction of pixels thresholded
284286vs. threshold in step 3.3).
287+ \end {sloppypar }
285288
286289% LocalWords: WebQ MATLAB DSP
0 commit comments