% 在GUI裡使用了一個axes
x = imread('test.bmp');
n = 7;
z = zeros(ceil([length(x(:,1,1))/n,length(x(1,:,1))/n]));
y = ones(ceil([length(x(:,1,1))/n,length(x(1,:,1))/n])*n)*255;
y(1:size(x,1),1:size(x,2)) = rgb2gray(x);
z = z'; y = y';
u = char(z);
for i = 1:length(y(:,1))/n
for j = 1:length(y(1,:))/n
z(i,j) = mean(mean(y((i-1)*n+1:i*n,(j-1)*n+1:j*n)));
end
end
mi = min(z(:));
d = (max(z(:)) - mi)/6; %level = 6
u(find(z < mi+d)) = '@';
u(find(z >= mi+d & z < mi+2*d)) = 'm';
u(find(z >= mi+2*d & z < mi+3*d)) = 'n';
u(find(z >= mi+3*d & z < mi+4*d)) = 'v';
u(find(z >= mi+4*d & z < mi+5*d)) = '/';
u(find(z >= mi+5*d)) = '.';
set(handles.figure1,'Position',[90 50 size(z,1) size(z,2)/3]);
set(handles.axes1,'Position',[0 0 size(z,1) size(z,2)/3]);
drawnow;
for i = 1:length(u(:,1))
for j = 1:length(u(1,:))
text((i)/length(u(:,1)),(length(u(1,:))-j)/length(u(1,:)),u(i,j),'fontsize',4);
end
end
axis off
im = getframe(handles.figure1); % 擷取畫面
[filename, pathname] = uiputfile({'*.bmp','BMP-files (*.bmp)';'*.jpg','JPEG (*.jpg)';'*.tif','TIF (*.tif)';'*.*','All Files (*.*)'},'Pick a file');
imwrite(uint8(im.cdata),[pathname filename]);
原圖
結果
沒有留言:
張貼留言