function bmp=convert2BMP(img)

本文介绍了一种将4096灰度级别的图像转换为256灰度级别图像的方法。通过将输入图像的数据类型转换为double,并使用floor(img/16)进行下取整操作,实现了灰度级的有效减少。
部署运行你感兴趣的模型镜像
function bmp=convert2BMP(img)
%convert an image of 4096 gray levels to an img of 256 gray levels
%input: img is of 4096 gray levels
%output: bmp is of 256 gray levels
img=double(img);
bmp=uint8(floor(img/16));
%imshow(bmp);
 

您可能感兴趣的与本文相关的镜像

Llama Factory

Llama Factory

模型微调
LLama-Factory

LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

#include <opencv2/opencv.hpp> #include <iostream> #include <fstream> #include <string> #include <vector> #include <direct.h> // _mkdir #include <io.h> // _access using namespace cv; using namespace std; std::string rawvideo_pathname = "D://C++2//c++//teacher task//1_sino20250829_Head1_1280_1024_480_N12_du308_angle240_sdd606_sod365_90kV_25mA_0p3cu_pulse15ms_24fps_Gain7_shake.raw"; std::string outputpath = "D://work//Medicalimaging//CT//data_3//20241221//results//DETECT_openCV//"; std::string rawname = extension_removal(getFileName_FromPath(rawvideo_pathname)); // 或者使用 std::string filename = last_separator - inputpath.begin(); std::string Targetcenters_path = outputpath + rawname + "_TCtxt/"; if (_access(Targetcenters_path.c_str(), 0) == -1) //如果文件夹不存在 { _mkdir(Targetcenters_path.c_str()); //则创建 } int imageHeight = 1024; int imageWidth = 1280; int slice = 480; int imagetype = 5; vector<cv::Mat> ImageS0, ImageS1; read_rawvideo(rawvideo_pathname, imageHeight, imageWidth, slice, ImageS0, imagetype); rawImagesConvertBMP(ImageS0, ImageS1); // 需要实现这个函数,假设它将原始图像数据转换为BMP格式 // Helper Functions std::string getFileName_FromPath(const std::string& pathname) { string d_slash = "/\\"; size_t index_of_slash = pathname.find_last_of(d_slash); string file_name = pathname.substr(index_of_slash + 1); return file_name; } std::string extension_removal(const string& name_of_file) { size_t index_of_period = name_of_file.find_last_of('.'); string file_without_extension = name_of_file.substr(0, index_of_period); return file_without_extension; } // Read raw video data (modify this function based on raw data format) void read_rawvideo(std::string inputpath, int& H, int& W, int& slice, vector<cv::Mat>& Images, int image_type) { int resolution = H * W; ifstream myData(inputpath, ios::binary); if (!myData) { cout << "文件不存在" << endl; exit(100); } else { int n = 0; char buf[sizeof(int)]; // Assuming each element is an integer (modify based on your data type) vector<cv::Mat> Images_1D; cv::Mat img_1D, img; if (image_type == 1) // Assuming this means 8-bit depth { img_1D = Mat::zeros(resolution, 1, CV_8UC1); } else if (image_type == 2) // Assuming 16-bit depth { img_1D = Mat::zeros(resolution, 1, CV_16UC1); } // Add more types as needed based on your data while (myData.read(buf, sizeof(buf))) { img_1D.at<uchar>(n) = buf[0]; // Assuming 1 byte per element; modify if needed n++; if (n == resolution) { img = img_1D.reshape(0, H); // Reshape to (H, W) Images.push_back(img); img_1D = Mat::zeros(resolution, 1, CV_8UC1); // Reset img_1D n = 0; } } } } // Placeholder function: rawImagesConvertBMP void rawImagesConvertBMP(const vector<cv::Mat>& ImageS0, vector<cv::Mat>& ImageS1) { // This function will convert raw images to BMP files // Placeholder code to save images as BMP format for (size_t i = 0; i < ImageS0.size(); i++) { std::string filename = "image_" + std::to_string(i) + ".bmp"; imwrite(filename, ImageS0[i]); // Save the image as BMP ImageS1.push_back(ImageS0[i]); } } 这是一段c++识别raw文件的语言,详细说说什么意思
09-19
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值