Home » Source Code » 数字图像处理

数字图像处理

wei...
2018-04-01 21:42:30
The author
View(s):
Download(s): 0
Point (s): 1 
Category Category:
c++c++ AllAll

Description

#include
#include
#include
#include


using namespace std;
using namespace cv;


int main()
{
//图像读取
Mat image = imread("D:/ps/meiyuan.png");


//判断图像读取是否有问题
if (!image.data)
{
cout << "image read is error!" << endl;
return 0;
}


//图像基本信息输出
cout << "image Info:Height:" << image.size().height << " Width:" << image.size().width << endl;


//原始图像显示
namedWindow("Original Image");
imshow("Original Image", image);
imwrite("original.jpg", image);


//处理图像
Mat image_tmp = image.clone();
int nl = image.rows;
int nc = image.cols * image.channels(); //实际列
if (image.isContinuous())
{
nc = nc * nl;
nl = 1;
}
int i, j;
int n;
uchar *data;
uchar *data_tmp;
int rang_min, rang_max;
for (n = 1; n <= 8; n++)
{
rang_min = pow(2, n - 1);//2^(n-1)
rang_max = pow(2, n);
for (j = 0; j < nl; j++)
{
data = image.ptr(j);
data_tmp = image_tmp.ptr(j);
for (i = 0; i < nc; i++)
{
if (data[i] >= rang_min && data[i] < rang_max)
data_tmp[i] = 255;
else
data_tmp[i] = 0;
}
}


switch (n)
{
case 1:
namedWindow("Bit Level 1");
imshow("Bit Level 1", image_tmp);
imwrite("Bit_Level_1.jpg", image_tmp);
break;
case 2:
namedWindow("Bit Level 2");
imshow("Bit Level 2", image_tmp);
imwrite("Bit_Level_2.jpg", image_tmp);
break;
case 3:
namedWindow("Bit Level 3");
imshow("Bit Level 3", image_tmp);
imwrite("Bit_Level_3.jpg", image_tmp);
break;
case 4:
namedWindow("Bit Level 4");
imshow("Bit Level 4", image_tmp);
imwrite("Bit_Level_4.jpg", image_tmp);
break;
case 5:
namedWindow("Bit Level 5");
imshow("Bit Level 5", image_tmp);
imwrite("Bit_Level_5.jpg", image_tmp);
break;
case 6:
namedWindow("Bit Level 6");
imshow("Bit Level 6", image_tmp);
imwrite("Bit_Level_6.jpg", image_tmp);
break;
case 7:
namedWindow("Bit Level 7");
imshow("Bit Level 7", image_tmp);
imwrite("Bit_Level_7.jpg", image_tmp);
break;
case 8:
namedWindow("Bit Level 8");
imshow("Bit Level 8", image_tmp);
imwrite("Bit_Level_8.jpg", image_tmp);
break;
default:
break;
}
}






//显示图像
//namedWindow("Process Image");
//imshow("Process Image", image);


//保存图像
imwrite("result.JPG", image);


waitKey(0);


return 0;
}
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
Sponsored links

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

数字图像处理 (4.46 MB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D