You may use MATLAB to visually display the input and output files and demo outpu
ID: 2082996 • Letter: Y
Question
You may use MATLAB to visually display the input and output files and demo output. Matlab commands g imread ('c: Aloc image ext') read the image Scheck to see the size of the image size ig) g rgb2 gray (g) Sapply this is he image is 3-D matrix (3rd dimension is color 7e (g) et dimension in m and g g randn (m, n) Sadd some white noise to the image g reshape (g, 1, m*n); Sreshapes matrix into a vector append to row col to the vector fid fopen imagefile 'w'); Simage file is the name of the file Sw-open for writing fwrite (fid g, uinL8'); ss Lore into file a unsigned b e close (fid) display regular images g mre ad picture ext. read image images (g) display $show as black /white colormap (grayscale) If you want to display the contents of your file pre/post processing: sopen file for eading fid fopen img 'r') rc fread (fid, 2) Sread firs 2 by Les (row, col) Sread the stored vector of size rxc y fread (fid, rc (1)*rc (2)); reshape (y, 200, 200 i sreshape vector into a matrix imagesc (y') s display colormap (grayscle) fclose (fid)Explanation / Answer
at first make sure that the file you want to read is in your matlab directory
a) you may use MATLAB to visually display the input and output files and demo out
enter the following program
g=imread('media.png');
[m n k]=size(g); %m and n has to be defined so as to use it afterwards
g=rgb2gray(g);
[r c]=size(g);
g=g+randi([1 255],[m n],'uint8'); % class of the integers should be same
% g=[r c g]; this step is not possible sice the dimensions of
% r,c and g are different
fid=fopen('imagefile','w');
fwrite(fid,g,'uint8');
fclose(fid);
b) display regular images:
enter the following code
X=imread('media.png');
figure (1)
imshow(X)
g=rgb2gray(X);
figure (2);
imshow(g)
c) If you want yo display the contents of your file pre/post processing:
enter the following code
fid=fopen('media.png','r');
[r c]=fread(fid,inf,'*uint16'); % simply putting only reads the first
% 2 digits in the matrix and not 2 bytes
l=fix(sqrt(c));
for i=1:l^2;
b(i,1)=r(i,1);
end
y=reshape(b,l,l);
figure (1)
imshow(y')
fclose(fid);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.