turboc中的直方图均衡化 我试图在Windows上使用Turbo C++在C编程中执行直方图均衡化,但是由于某种原因,我得到了这个错误。 链接器错误:模块直方图中未定义符号。\u四舍五入。c
我读过这个 我还尝试了选项-->链接器-->库,并检查了图形库选项,但仍然出现相同的错误 我的代码turboc中的直方图均衡化 我试图在Windows上使用Turbo C++在C编程中执行直方图均衡化,但是由于某种原因,我得到了这个错误。 链接器错误:模块直方图中未定义符号。\u四舍五入。c,c,image-processing,turbo-c++,C,Image Processing,Turbo C++,我读过这个 我还尝试了选项-->链接器-->库,并检查了图形库选项,但仍然出现相同的错误 我的代码 // C program to perform histogram equalisation to adjust contrast levels // All the needed library functions for this program #include <fcntl.h> #include <math.h> #include <stdio.h
// C program to perform histogram equalisation to adjust contrast levels
// All the needed library functions for this program
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Function to perform histogram equalisation on an image
// Function takes total rows, columns, input file name and output
// file name as parameters
void histogramEqualisation(int cols, int rows,
char* input_file_name, char* output_file_name)
{
// creating image pointer
unsigned char* image;
// Declaring 2 arrays for storing histogram values (frequencies) and
// new gray level values (newly mapped pixel values as per algorithm)
int hist[256] = { 0 };
int new_gray_level[256] = { 0 };
// Declaring other important variables
int input_file, output_file, col, row, total, curr, i;
// allocating image array the size equivalent to number of columns
// of the image to read one row of an image at a time
image = (unsigned char*)calloc(cols, sizeof(unsigned char));
// opening input file in Read Only Mode
input_file = open(input_file_name, O_RDONLY);
if (input_file < 0) {
printf("Error opening input file\n");
exit(1);
}
// creating output file that has write and read access
output_file = creat(output_file_name, 0666);
if (output_file < 0) {
printf("Error creating output file\n");
exit(1);
}
// Calculating frequency of occurrence for all pixel values
for (row = 0; row < rows; row++) {
// reading a row of image
read(input_file, &image[0], cols * sizeof(unsigned char));
// logic for calculating histogram
for (col = 0; col < cols; col++)
hist[(int)image[col]]++;
}
// calulating total number of pixels
total = cols * rows;
curr = 0;
// calculating cumulative frequency and new gray levels
for (i = 0; i < 256; i++) {
// cumulative frequency
curr += hist[i];
// calculating new gray level after multiplying by
// maximum gray count which is 255 and dividing by
// total number of pixels
new_gray_level[i] = round((((float)curr) * 255) / total);
}
// closing file
close(input_file);
// reopening file in Read Only Mode
input_file = open(input_file_name, O_RDONLY);
// performing histogram equalisation by mapping new gray levels
for (row = 0; row < rows; row++) {
// reading a row of image
read(input_file, &image[0], cols * sizeof(unsigned char));
// mapping to new gray level values
for (col = 0; col < cols; col++)
image[col] = (unsigned char)new_gray_level[image[col]];
// reading new gray level mapped row of image
write(output_file, &image[0], cols * sizeof(unsigned char));
}
// freeing dynamically allocated memory
free(image);
// closing input and output files
close(input_file);
close(output_file);
}
// driver code
int main()
{
// declaring variables
char* input_file_name;
char* output_file_name;
int cols, rows;
// defining number of rows and columns in an image
// here, image size is 512*512
cols = 512;
rows = 512;
// defining input file name (input image name)
// this boat_512_512 is a raw grayscale image
input_file_name = "boat_512_512";
enter code here
// defining output file name (output image name)
output_file_name = "boat_512_512_histogram_equalised";
// calling function to do histogram equalisation
histogramEqualisation(cols, rows, input_file_name, output_file_name);
return 0;
}
//执行直方图均衡以调整对比度级别的C程序
//此程序所需的所有库函数
#包括
#包括
#包括
#包括
#包括
//函数对图像执行直方图均衡
//函数获取所有行、列、输入文件名和输出
//作为参数的文件名
无效HistorogrameQualification(整数列、整数行、,
字符*输入文件名,字符*输出文件名)
{
//创建图像指针
无符号字符*图像;
//声明用于存储直方图值(频率)和
//新灰度值(根据算法新映射的像素值)
int hist[256]={0};
int new_gray_level[256]={0};
//声明其他重要变量
int输入\文件、输出\文件、列、行、总计、当前、i;
//分配与列数相等的图像数组大小
//一次读取图像的一行
image=(无符号字符*)calloc(cols,sizeof(无符号字符));
//以只读模式打开输入文件
输入文件=打开(仅输入文件名);
如果(输入_文件<0){
printf(“打开输入文件时出错”);
出口(1);
}
//创建具有写和读访问权限的输出文件
输出文件=创建(输出文件名称,0666);
如果(输出_文件<0){
printf(“创建输出文件时出错”);
出口(1);
}
//计算所有像素值的出现频率
对于(行=0;行<行;行++){
//读取一行图像
读取(输入_文件,&image[0],cols*sizeof(无符号字符));
//直方图计算逻辑
for(col=0;col
请帮忙不是解决问题的方法,但我强烈建议停止使用Turbo C++。它属于历史。Turbo C的数学库的可能副本不提供
round
。在您的情况下,您可能不需要整数数学:(255*curr+total/2)/total
如果255*curr
没有溢出int
或者只需使用255.0*curr/total+0.5
并让到int
的隐式转换切断小数部分。添加float round(float x)怎么样{返回楼层(x+0.5)}
到您的代码…或\u round
…请检查您是否也链接了数学库,可能名为“m”不是你的问题的解决方案,但是我强烈建议停止使用Turbo C++。它属于历史。Turbo C的数学LIB的可能副本不提供<代码>圆<代码>。在这种情况下,你可能会逃脱整数数学:<代码>(255*Curr+总数/ 2)。/total如果255*curr
没有溢出int
或只使用255.0*curr/total+0.5
并让到int
的隐式转换切断小数部分。添加浮动圆(浮动x){返回层(x+0.5);}
到您的代码…或\u round
…请检查您是否也链接了数学库,可能名为“m”。