diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b777ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# Visual Studio / Visual C++ +.vs/ +*.suo +*.user +*.userosscache +*.sln.docstates +*.VC.db +*.VC.opendb +ipch/ +obj/ +[Bb]uild/ +[Bb]in/ +Debug*/ +Release*/ +x64/ +*.vcxproj.user +*.filters.user + +# Visual C++ generated +*.o +*.obj +*.pdb +*.idb +*.ilk +*.exp +*.lib +*.dll +*.exe + +# IntelliSense / database +*.sdf +*.opensdf +*.ncb + +# Logs and temp +*.log +*.cache +*.tmp +*.temp + +# OS files +.DS_Store +Thumbs.db +desktop.ini + +# Raw image / data files (ignore large binary test files) +*.raw +result.txt diff --git a/lab-1/lab1/.gitignore b/lab-1/lab1/.gitignore new file mode 100644 index 0000000..b777ac0 --- /dev/null +++ b/lab-1/lab1/.gitignore @@ -0,0 +1,48 @@ +# Visual Studio / Visual C++ +.vs/ +*.suo +*.user +*.userosscache +*.sln.docstates +*.VC.db +*.VC.opendb +ipch/ +obj/ +[Bb]uild/ +[Bb]in/ +Debug*/ +Release*/ +x64/ +*.vcxproj.user +*.filters.user + +# Visual C++ generated +*.o +*.obj +*.pdb +*.idb +*.ilk +*.exp +*.lib +*.dll +*.exe + +# IntelliSense / database +*.sdf +*.opensdf +*.ncb + +# Logs and temp +*.log +*.cache +*.tmp +*.temp + +# OS files +.DS_Store +Thumbs.db +desktop.ini + +# Raw image / data files (ignore large binary test files) +*.raw +result.txt diff --git a/lab-1/lab1/lab1.cpp b/lab-1/lab1/lab1.cpp new file mode 100644 index 0000000..4836f0c --- /dev/null +++ b/lab-1/lab1/lab1.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#define H 1210 +#define W 1240 + +using namespace std; + +int main() +{ + unsigned char* grey; + // 存灰度值的数组 + grey = new unsigned char[H * W]; + FILE* filetest; + //读取文件 + fopen_s(&filetest, "E:\\Digital image process\\lab-1\\第一次上机实验数据\\test.raw", "rb"); + fread(grey, sizeof(unsigned char), H * W, filetest); + + int i, j; + int* Pi_number = new int[256]; + for (i = 0; i < 256; i++) { + Pi_number[i] = 0; + } + for (i = 0; i < H; i++) { + for (j = 0; j < W; j++) { + Pi_number[grey[i * W + j]]++; + } + } + float* Pi = new float[256]; + for (i = 0; i < 256; i++) { + Pi[i] = (float)Pi_number[i] / (H * W); + } + + //计算均值和标准差 + float mean = 0; + for (i = 0; i < 256; i++) { + mean += (float)i * Pi[i]; + } + + float variance = 0; + for (i = 0; i < 256; i++) { + variance += Pi[i] * (i - mean) * (i - mean); + } + float stdvar = sqrt(variance); + + FILE* fileout; + + fopen_s(&fileout, "E:\\Digital image process\\lab-1\\第一次上机实验数据\\result.txt", "w"); + + fprintf(fileout, "完成人:测绘2401 24110901003 毕爽爽 \n"); + fprintf(fileout, "均值:%f,标准差:%f\n", mean, stdvar); + for (i = 0; i < 256; i++) { + fprintf(fileout, "灰度值为%d的像素个数:%d,频率:%f\n", i, Pi_number[i], Pi[i]); + } + + fclose(filetest); + fclose(fileout); +} \ No newline at end of file diff --git a/lab-1/lab1/lab1.slnx b/lab-1/lab1/lab1.slnx new file mode 100644 index 0000000..7732cf3 --- /dev/null +++ b/lab-1/lab1/lab1.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/lab-1/lab1/lab1.vcxproj b/lab-1/lab1/lab1.vcxproj new file mode 100644 index 0000000..0fa5bc7 --- /dev/null +++ b/lab-1/lab1/lab1.vcxproj @@ -0,0 +1,138 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 18.0 + Win32Proj + {616cb777-9ff4-41ac-90cc-cf53a86421e0} + lab1 + 10.0 + + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + + + + + + + + \ No newline at end of file diff --git a/lab-1/lab1/lab1.vcxproj.filters b/lab-1/lab1/lab1.vcxproj.filters new file mode 100644 index 0000000..5e99390 --- /dev/null +++ b/lab-1/lab1/lab1.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + + + + \ No newline at end of file