将C++程序转换成matlab程序
#include"stdio.h"main(){/*只处理16、24、32真彩色位图*/longbiwidth,biheight,i,j,N,M,T;shortbibit...
#include "stdio.h"
main( ) { /*只处理16、24、32真彩色位图*/
long biwidth,biheight,i,j,N,M,T;
short bibitcount;
unsigned char x;
FILE *fp1; FILE *fp2; FILE *fp3;
fp1=fopen("flower.bmp","rb");
fseek(fp1,18,0);
fread(&biwidth,4,1,fp1); /*读图像的宽度*/
fseek(fp1,22,0);
fread(&biheight,4,1,fp1); /*读图像的高度*/
fseek(fp1,28,0);
fread(&bibitcount,2,1,fp1); /*读颜色位数*/
printf("The biwidth of the image is:%d\n",biwidth); /*显示图像的宽度*/
printf("The biheight of the image is:%d\n",biheight); /*高度*/
printf("The bibitcount of the image is:%d\n",bibitcount); /*颜色位数*/
fp2=fopen("head.txt","wb");
for(i=0;i<54;i++) {
fseek(fp1,i,0);
fread(&x,1,1,fp1);
fprintf(fp2,"%x\t",x); /*把位图文件头、信息头写到head.txt中去*/
}
fclose(fp2);
N=biwidth*(bibitcount/8);
if(N%4==0)
M=N;
else M=N+4-(N%4); /*算出每一行的字节数M*/
fp3=fopen("data.txt","wb");
for(i=0;i<biheight;i++){
for(j=0;j<N;j++){
T=54+(M*i)+j;
fseek(fp1,T,0);
fread(&x,1,1,fp1);
fprintf(fp3,"%d\t",x); /*把位图数据写到data.txt中去*/
}
}
fclose(fp3);
fclose(fp1);
getch();
}
能帮忙把上面的C++程序转成matlab程序表示。。 展开
main( ) { /*只处理16、24、32真彩色位图*/
long biwidth,biheight,i,j,N,M,T;
short bibitcount;
unsigned char x;
FILE *fp1; FILE *fp2; FILE *fp3;
fp1=fopen("flower.bmp","rb");
fseek(fp1,18,0);
fread(&biwidth,4,1,fp1); /*读图像的宽度*/
fseek(fp1,22,0);
fread(&biheight,4,1,fp1); /*读图像的高度*/
fseek(fp1,28,0);
fread(&bibitcount,2,1,fp1); /*读颜色位数*/
printf("The biwidth of the image is:%d\n",biwidth); /*显示图像的宽度*/
printf("The biheight of the image is:%d\n",biheight); /*高度*/
printf("The bibitcount of the image is:%d\n",bibitcount); /*颜色位数*/
fp2=fopen("head.txt","wb");
for(i=0;i<54;i++) {
fseek(fp1,i,0);
fread(&x,1,1,fp1);
fprintf(fp2,"%x\t",x); /*把位图文件头、信息头写到head.txt中去*/
}
fclose(fp2);
N=biwidth*(bibitcount/8);
if(N%4==0)
M=N;
else M=N+4-(N%4); /*算出每一行的字节数M*/
fp3=fopen("data.txt","wb");
for(i=0;i<biheight;i++){
for(j=0;j<N;j++){
T=54+(M*i)+j;
fseek(fp1,T,0);
fread(&x,1,1,fp1);
fprintf(fp3,"%d\t",x); /*把位图数据写到data.txt中去*/
}
}
fclose(fp3);
fclose(fp1);
getch();
}
能帮忙把上面的C++程序转成matlab程序表示。。 展开
展开全部
生成的速度比较慢。因为是直接一个个写文件。
fp1=fopen('flower.bmp','r');
fseek(fp1,18,'bof');
biwidth=fread(fp1,1,'int32');
fseek(fp1,22,'bof');
biheight=fread(fp1,1,'int32');
fseek(fp1,28,'bof');
bibitcount=fread(fp1,1,'int16');
disp(['The biwidth of the image is:'棚逗,num2str(biwidth)])
disp(['The biheight of the image is:',num2str(biheight)])
disp(['The bibitcount of the image is:',num2str(bibitcount)])
fp2=fopen('head1.txt','w');
fseek(fp1,0,'bof');
for i=1:54
x=fread(fp1,1,'uint8');
fprintf(fp2,'%s\t',dec2hex(x));
end
fclose(fp2);
N=biwidth*(bibitcount/御尺8);
if mod(N,4)==0
M=N;
else
M=N+4-mod(N,4);
end
fp3=fopen('data1.txt','w');
for i=1:biheight
for j=1:N
T=54+(M*(i-1))+j-1;
fseek(fp1,T,'bof');
x=fread(fp1,1,'uint8');
fprintf(fp3,'%d\t'镇和高,x);
end
end
fclose(fp3);
fclose(fp1);
fp1=fopen('flower.bmp','r');
fseek(fp1,18,'bof');
biwidth=fread(fp1,1,'int32');
fseek(fp1,22,'bof');
biheight=fread(fp1,1,'int32');
fseek(fp1,28,'bof');
bibitcount=fread(fp1,1,'int16');
disp(['The biwidth of the image is:'棚逗,num2str(biwidth)])
disp(['The biheight of the image is:',num2str(biheight)])
disp(['The bibitcount of the image is:',num2str(bibitcount)])
fp2=fopen('head1.txt','w');
fseek(fp1,0,'bof');
for i=1:54
x=fread(fp1,1,'uint8');
fprintf(fp2,'%s\t',dec2hex(x));
end
fclose(fp2);
N=biwidth*(bibitcount/御尺8);
if mod(N,4)==0
M=N;
else
M=N+4-mod(N,4);
end
fp3=fopen('data1.txt','w');
for i=1:biheight
for j=1:N
T=54+(M*(i-1))+j-1;
fseek(fp1,T,'bof');
x=fread(fp1,1,'uint8');
fprintf(fp3,'%d\t'镇和高,x);
end
end
fclose(fp3);
fclose(fp1);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询