cyfile / Matlab-miscellanies

各种Matlab代码
0 stars 0 forks source link

魔兽地形文件(war3map.w3e war3map.doo)制作 #1

Open 213cy opened 9 years ago

213cy commented 9 years ago
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 更改地形放置文件war3map.w3e 需要图片矩阵D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cd('C:\Documents and Settings\morlet\桌面')
%
fileID = fopen('war3map.w3e','r');%
w3e=fread(fileID,'_uint8');
fclose(fileID);
ind=(73+1:7:length(w3e));
w3e(ind)=D(:);
%
fileID = fopen('aaa\war3map.w3e','w');%
fwrite(fileID, w3e)
fclose(fileID)
%%
%hist(double(w3e(ind)))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 更改树木放置文件war3map.doo 需要图片矩阵C
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cd('C:\Documents and Settings\morlet\桌面')
%
fileID = fopen('war3map.doo','r');%
% ftell(fileID)
% fseek(fileID, 24, -1)
% A = fread(fileID,2,'_single')
% fread(fileID,2,'_float')
% fread(fileID,2,'_float32')
doo=fread(fileID,'_uint8');
fclose(fileID);
%%
[row,col] = find(C==3);
x=num2hex(single((col-65)_128));
y=num2hex(single((65-row)_128));
M=size(x,1)-1;
%xy=zeros(M,8);
doo(25:42:25+42_M)=hex2dec(x(:,7:8));
doo(26:42:26+42_M)=hex2dec(x(:,5:6));
doo(27:42:27+42_M)=hex2dec(x(:,3:4));
doo(28:42:28+42_M)=hex2dec(x(:,1:2));
doo(29:42:29+42_M)=hex2dec(y(:,7:8));
doo(30:42:30+42_M)=hex2dec(y(:,5:6));
doo(31:42:31+42_M)=hex2dec(y(:,3:4));
doo(32:42:32+42_M)=hex2dec(y(:,1:2));
%%
fileID = fopen('aaa\war3map.doo','w');%
fwrite(fileID, doo)
fclose(fileID)
%%
%char(doo(17:20))
% doo(25:42:25+42_M)
% doo(25:28)
% doo(29:32)
213cy commented 9 years ago

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 准备图片 第一种方法 生成 C ,D %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A=imread('xi.jpg','jpg'); B=rgb2gray(A); C=B; %imshow(B) %imshow(b) %% n=6; bb=sort(B(:)); N=length(bb); bind=linspace(1,N,n); tick=bb(ceil(bind)); %% val=[3 5 4 2 0]; %val=0:4; for k=1:n-1 C( tick(k)<=B & B<tick(k+1) )=val(k); end C( B==tick(n) )=val(k); imshow(C,[]) %% D=rot90(C,3); imshow(D,[])

213cy commented 9 years ago

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 准备图片 第二种方法 生成 D %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sqrt((7692-69)/7) sqrt((116556-69)/7) %% A=imread('00.jpg','jpg'); A=imresize(A,[129,129]); B=rgb2gray(A); %% C=double(B)/255; bb=sort(C(:)); bind=linspace(0,1,7); N=length(bb); %% % for k=2:7 % bb(ceil(N_bind(k))) % C(C<=bb(ceil(N_bind(k))))=9-k; % end %D=rot90(C-2,3); %% C=double(B)/255; C(C<=0)=5; C(C<=127/256)=4; C(C<=255/256)=2; C(C<=1)=0; D=rot90(C,3); %% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % imshow(D,[]) % imshow(B,[]) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

213cy commented 9 years ago

示例图片 xi.jpg xi 00.jpg 00 0.jpg 0

213cy commented 4 years ago

y4 无标题

用地形装饰物构成简笔画

A=imread('y4','jpg');
B=rgb2gray(A);
% imshow(B)
%%
% imcontrast
% graythresh(B)
% BW = imbinarize(B);
% C = imbinarize(B,100/255);
C = imbinarize(B, 'adaptive','Sensitivity',0.4,'ForegroundPolarity','dark');
% imshow(C)

D = ~bwareafilt(~C, 7);
% imshow(D)
% D3 = ~bwareaopen(~C,20);
% imshowpair(C,D,'diff')

SE = strel('diamond',2);
% A= imdilate(D,SE);
A= imerode(D,SE);
imshow(A)

J = imresize(A,0.1);
imshow(J)
%%
[r,c] = find(J==0);
fileID = fopen('war3map.doo','r+');
fseek(fileID, 32, -1);
fwrite(fileID,16*[c';-r'],'2*float',42,'l')
fclose(fileID);
%%
fileID = fopen('war3map.doo','r');
% ftell(fileID)
fseek(fileID, 24, -1);
t_beg=fread(fileID,[2,4],'2*float',42,'l');
% num2hex(single(t_beg))