MATLAB Help: The input is a jumbled character array and two vectors (representin
ID: 3667537 • Letter: M
Question
MATLAB Help:
The input is a jumbled character array and two vectors (representing a row and column shift) and output is to produce a an ASCII image. The last elements in the row and column shift vectors represent the number of shifts to make, while all other numbers in the vector represent which row/columns to shift. Positive row shifts move elements to the right and positive column shifts move elements down. Negative shifts move in the other direction. The code should be that the rows move first and then the columns.
Explanation / Answer
Hi!
2. ASCII text containg file = u must a filename.txt in at any location and then enter its path in the second part of the code
%This program is which creates ASCII Images
function pic;
[FileName,PathName] = uigetfile('*.jpg','Select any image');
y= [PathName,FileName];
i=imread(y); % reading the image
if (length(size(i))==3) % if image is color = real time 24 bit image
i=rgb2gray(i);
end
gmax = 27; % Maximum number of intensity character
i=imresize(i,[80 100],'nearest'); % dimensions to be written on notepad file
image=double(i); % for arithmetic operation
[rows cols c]=size(image);
image = image - min(min(image)); % to make minimum value 0
image = (image/max(max(image))); % to make maximum value 1
image = round(image*(gmax-1) + 1); % Scaling the values b/w 1 - 27
picture = char(zeros(rows,cols)); % creating a matrix where we can store characters
for r = 1: rows
for c = 1:cols
B=image(r,c); %reading each pixel
% this section reads each pixcel from the image
switch(B)
case(28)
A =' ';
picture(r,c)=A;
case(27)
A ='.';
picture(r,c)=A;
case(26)
A ='`';
picture(r,c)=A;
case(25)
A =char(39);
picture(r,c)=A;
case(24)
A =':';
picture(r,c)=A;
case(23)
A =',-^'; % all these characters are ' intensity wise '
picture(r,c)=A(round((rand(1)*2+1)));
case(22)
A ='!"~'; % This intensity measure are taking through a vb6 program
picture(r,c)=A(round((rand(1)*2+1)));
case(21)
A =';_';
picture(r,c)=A(round((rand(1)+1)));
case(20)
A ='()/<>|';
picture(r,c)=A(round((rand(1)*6+1)));
case(19)
A ='*?';
picture(r,c)=A(round((rand(1)+1)));
case(18)
A ='=[]{}';
picture(r,c)=A(round((rand(1)*4+1)));
case(17)
A ='+';
picture(r,c)=A;
case(16)
A ='%17cilor';
picture(r,c)=A(round((rand(1)*7+1)));
case(15)
A ='$&Jjstx';
picture(r,c)=A(round((rand(1)*6+1)));
case(14)
A ='23Cfv';
picture(r,c)=A(round((rand(1)*4+1)));
case(13)
A ='5ILTeuz';
picture(r,c)=A(round((rand(1)*6+1)));
case(12)
A ='0469OYw'; % all these have same intensity ,so i am picking it randomly so that
picture(r,c)=A(round((rand(1)*6+1))); %nobody thinks that this is written by specific characters
case(11)
A ='8GPSXZany';
picture(r,c)=A(round((rand(1)*8+1)));
case(10)
A ='ADFVbd';
picture(r,c)=A(round((rand(1)*5+1)));
case(9)
A ='QRUghkpq';
picture(r,c)=A(round((rand(1)*7+1)));
case(8)
A ='m';
picture(r,c)=A;
case(7)
A ='E';
picture(r,c)=A;
case(6)
A ='BKW';
picture(r,c)=A(round((rand(1)*2+1)));
case(5)
A ='#';
picture(r,c)=A;
case(4)
A ='@';
picture(r,c)=A;
case(3)
A ='H';
picture(r,c)=A;
case(2)
A ='N';
picture(r,c)=A;
case(1)
A ='M';
picture(r,c)=A;
end
end
end
[file,path] = uiputfile('*.txt','Save Ascii Image as');
% u must a filename.txt in at any location and then enter its path here
filename = [path,file];
f = fopen(filename,'wt');
for r = 1: rows
fprintf(f,'%s ',picture(r,:)); % is similar as in C i-e 'enter' at the end of one row(see help fprintf)
end
fclose(f);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.