I'd recommend working in teams of two on the project.
load filenameFilename would use single quotes, e.g.
load 'echar512.mat'which will load a 512 x 512 matrix
echart
.
You can load an image in a standard image format (e.g. PNG or JPG) using
imread(filename)
imshow(echart)imshow(image) will display the image by clipping the pixel values outside a certain range. The range depends on the data type of the image. In our case, the image is double and the range is [0, 1] where 0 corresponds to black and 1 to white.
We can specify the range of pixel values to show:
imshow(echart, [0 255]);A more general way to display the full range of pixel values in an image is
imshow(echart, []);
You can add a title when displaying an image by using the following code:
load echar512.mat hAxes = axes(figure); hImage = imshow(echart, [], 'Parent', hAxes); title(hAxes, 'Original echart image');
y2 = filter(b, 1, x, [], 2);Alternately, if b is a row vector, then you could use
y2 = conv2(x, b);
Apply a 1-D finite impulse response (FIR) filter with filter coefficients b down each column of an image x to produce a new image y1:
y1 = filter(b, 1, x, [], 1);Alternately, if b is a column vector, then you could use
y1 = conv2(x, b);You can convert a row vector into a column vector using the transpose operator that is a single quote:
bcolvec= browvec';
Here are the visual effects after applying the first-order difference filter along each row or column of an image:
imshow(image, [])
so the pixel values are displayed full scale and
not clipped.
Here is my code for Section 2.5:
% The load command will define a Matlab matrix echart. load echar512.mat % Display the image. hAxes = axes(figure); hImage = imshow(echart, [], 'Parent', hAxes); title(hAxes, 'Original echart image'); % Apply a first-order difference filter along the rows. % Display the resulting image. bdiffh = [1, -1]; yy1 = conv2(echart, bdiffh); hAxes1 = axes(figure); hImage1 = imshow(yy1, [], 'Parent', hAxes1); title(hAxes1, 'echart image filtered with [1 -1] along the rows'); % Apply a first-order difference filter along the columns. % Display the resulting image. bdiffh = [1, -1]; yy2 = conv2(echart, bdiffh'); hAxes2 = axes(figure); hImage2 = imshow(yy2, [], 'Parent', hAxes2); title(hAxes2, 'echart image filtered with [1 -1] along the columns');
Here is the Matlab code to define the 1-D impulse responses for 2-D LTI FIR filters 1 and 2:
% h1[n] has non-zero coefficients of 1 and -q: q = 0.9; h1 = [ 1 -q ]; % h2[n] = r^n for 0 <= n <= M and zero elsewhere: r = 0.9; M = 22; n = 0 : M; h2 = r .^ n;
Here's the ideal image restoration filter and how it relates to the one we're using.
Section 3.2.2 asks us to find the "worst case error in order to say how big the ghosts are relative to “black-white” transitions which are 0 to 255," and later in 3.3.3 we are asked to convert that error to a value in gray scale from 0 to 255. We can compute the worst case error on a pixel-by-pixel basis between image1 and image2 as follows where image1 and image2 would need to have the same dimensions:
imageDiff = image1 - image2; imageDiffAbs = abs(imageDiff); imageDiffAbsWorstCase = max(max(imageDiffAbs));Note that max(ImageDiffAbs) takes the maximum of each row of imageDiffAbs. The mean squared error (MSE) would add the entries in imageDiffAbs, and the normalized mean square error would add the entries in imageDiffAbs and divide by the number of pixels.
The lab asks you to find ways to compare two images. Matlab has several standard Image Quality Metrics:
immse
to compute the mean squared error (MSE) where a lower score is better,
but the scores might not align well with human perception of quality.
psnr
to compute the peak signal-to-noise ratio (PSNR) in dB where a higher score is better,
but the scores might not align well with human perception of quality.
ssim
to compute the structural similarity (SSIM) index on a scale of 0 to 1
where a higher score is better, and the scores align well with human perception of quality.
Our reference image, echart, has 512 row and 512 columns.
If you used the conv2
function, the images resulting from filtering echart are larger than echart,
and we can crop the resulting image to be the same size as echart:
ech90cropped = ech90(1:512, 1:512);We choose the first 512 columns in the first 512 rows because the convolution with the second filter will create large black borders on the right and on the bottom of the filtered image, and we'd like to remove the borders.
You do not have to crop if you are using the filter
function -- the filter
function only outputs as many samples as are in the input signal.
Last updated 11/03/23. Send comments to bevans@ece.utexas.edu