The following code, using Matlab, will convert a jpg file to ASCII Art. Who can provide a similar or better solution using SAS?
function [ imgascii ] = asciipic2( img, gcf, filename )
%asciis=[' .,:;rsiS52X39hGAHBM#&@'];
%asciis=[' .,:;risS52X3AGhHB9M#&@'];
%asciis=[' .,:;risA523XGShHM#B9&@'];
asciis=[' .,:;irXAs253hMHGS#9B&@'];
%asciis=['`''..-,:"_!~/\;*|^<+7r?v=iJLlYc)T{(}tsIVCxF325]1[uU4nzAXjfoZSyPweaKEHkGOh0M$N9#dq6RmDW%bpQ8Bg@&'];
temp=imread(img,'jpg');
imwrite(temp,'img.bmp','bmp');
img=imread('img.bmp','bmp');
img = imadjust(img, [0 0.8], [0 0.7]);
img=rgb2gray(img);
[rows, cols]=size(img);
%img=abs(hex2dec(dec2hex(img))-255);
img = 255 - double(img);
%img=reshape(img, rows, cols);
%extrarows=mod(rows,13);
%extracols=mod(cols,8);
extrarows=mod(rows,7);
extracols=mod(cols,4);
img=img(1:(end-extrarows),1:(end-extracols));
[rows, cols] = size(img);
%denseboxes=zeros(rows/13,cols/8);
denseboxes=zeros(rows/7,cols/4);
for ii=1:7%13
for oo=1:4%13
pixels=img(ii:7:end,oo:4:end);% pixels=img(ii:13:end,oo:8:end);
denseboxes = denseboxes + pixels;
end
end
%gcf=2.1;
denseboxes = denseboxes - min(min(denseboxes));
denseboxes = denseboxes./max(max(denseboxes));
denseboxes = denseboxes.^gcf;
map=linspace(min(min(denseboxes)),max(max(denseboxes)),23);
%map=max(max(denseboxes))+min(min(denseboxes))-logspace(log10(min(min(denseboxes))),log10(max(max(denseboxes))),23);
%imgascii=zeros(rows/13,cols/8);
imgascii=zeros(rows/7,cols/4);
for ii=1:(rows/7)%13
for jj=1:(cols/4)%8
which_char=1;
for kk=1:numel(map)
if denseboxes(ii,jj)>=map(kk)
which_char=which_char+1;
end
end
if(which_char>23),which_char=23; end
imgascii(ii,jj)=asciis(which_char);
end
end
imgascii=char(uint8(imgascii));
fid = fopen(filename, 'w');
for ii=1:size(imgascii,1)
fprintf(fid, '%s\r\n', imgascii(ii,:));
end
fclose(fid);
end
Arthur.T,
I think it is hard for SAS. There is not built-in function to process a photo.
JMP has built in image processing tools.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.