临时代码1111

临时代码1111,第1张

临时代码1111
#include 
#include 

using namespace std;
using namespace cv;
float sigmoid(float x)
{
	return (1 / (1 + exp(-x)));
}
int main(int argc, char** argv) {
	//int a = 100;
	//int b = 9;
	//std::cout << (a + b) / 2 << std::endl;
	//std::list values(262114, 3.14159265);
	//vector a(262114, 1.0);
	vector a;
	

	// 显示 vec 的原始大小
	cout << "vector size = " << a.size() << endl;

	// 推入 5 个值到向量中
	for (int i = 0; i < 786432; i++) {

		a.push_back((255.0/ 786432)*i);
	}


	Mat t1 = Mat(512, 512, CV_8UC1);
	t1.data;
	int width = t1.cols;
	int height = t1.rows;
	cout << width << " " << height << endl;
	float zz = a[10];
	std::cout << a[10] << endl;
	int index_num;
	for (int row = 0; row < height; row++) {
		for (int col = 0; col < width; col++) {
				index_num = row * 512 + col;
				t1.at(row, col) = (int) (sigmoid(a[index_num])*255);
				//cout << (int)a[index_num] << endl;
		}
	}
	Mat ImgGrayC1;
	t1.convertTo(ImgGrayC1, CV_8UC1);
	int pp1 = t1.at(500, 500);
	int pp = ImgGrayC1.at(500, 500);

	cout <<"data"<< (int)a[256512] << " " << pp << " " << pp1 << endl;
	Mat mask;
	cv::threshold(t1, mask, 127.0, 255.0,1);

	imshow("usm filter", mask);
	waitKey(0);
	destroyAllWindows();
	imwrite("D://2.jpg", t1);

	imwrite("D://1.jpg", ImgGrayC1);

	double min_val = 1000, max_val = -1000;
	for (int num_output = 0; num_output < 512 * 512 * 3; num_output++) {
		if (min_val > a[num_output]) {
			min_val = a[num_output];
		}
	}
	for (int num_output = 0; num_output < 512 * 512 * 3; num_output++) {
		a[num_output] = num_output - min_val;
	}
	for (int num_output = 0; num_output < 512 * 512 * 3; num_output++) {
		if (max_val < a[num_output]) {
			max_val = a[num_output];
		}
	}
	for (int num_output = 0; num_output < 512 * 512 * 3; num_output++) {
		a[num_output] = num_output/ max_val;
	}

	Mat image_bgr = Mat(512, 512, CV_8UC3);
	for (int row = 0; row < height; row++) {
		for (int col = 0; col < width; col++) {
			index_num = row * 512 + col;
			image_bgr.at(col, row)[0] = (int)((a[index_num]) * 255);
			image_bgr.at(col, row)[1] = (int)((a[index_num + 512 * 512]) * 255);
			image_bgr.at(col, row)[2] = (int)((a[index_num + 512 * 512 * 2]) * 255);
			//cout << (int)a[index_num] << endl;
		}
	}

	imwrite("D://3.jpg", image_bgr);


	

	
	



	

	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5714477.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存