#pragma once
//#include<iostream>
#include "HarrWavelet.h"
//CHarrWavelet::CHarrWavelet(MyImage &vSrcImage)
//{
// m_SrcImage = vSrcImage.clone();
//}
Mat MyImage::transToMat(Mat& voImage)
{
Mat Image=voImage.clone();
for (int i = 0; i < Height; i++)
{
for (int k = 0; k < Width; k++)
{
Image.ptr<uchar>(i)[k] = (Data[i][k]+0.5);
}
}
return Image;
}
void MyImage::getData(Mat& vSrcImage)
{
Height = vSrcImage.rows;
Width = vSrcImage.cols*vSrcImage.channels();
Data.resize(Height);
for (int i = 0; i < Height; i++)
{
Data[i].resize(Width);
}
for (int i = 0; i < Height; i++)
{
for (int k = 0; k < Width; k++)
{
Data[i][k] = vSrcImage.ptr<uchar>(i)[k];
}
}
}
MyImage Threshold::processedWithHard(MyImage& vSrcImage,double vVariance)
{
MyImage Image;
Image.Height = vSrcImage.Height;
Image.Width = vSrcImage.Width;
Image.Data = vSrcImage.Data;
double Threshold =vVariance;
int HalfHeight = Image.Height / 2;
int HalfWidth = Image.Width / 2;
for (int i = 0; i < HalfHeight; i++)
{
for (int j = HalfWidth; j < Image.Width; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
/* else
Image.Data[i][j] = Threshold;*/
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
for (int i = HalfHeight; i < Image.Height; i++)
{
for (int j = 0; j < HalfWidth; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
/*else
Image.Data[i][j] = Threshold;*/
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
for (int i = HalfHeight; i < Image.Height; i++)
{
for (int j = HalfWidth; j < Image.Width; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
else
Image.Data[i][j] = Threshold;
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
return Image;
}
MyImage Threshold::processedWithSoft(MyImage& vSrcImage,double vVariance)
{
MyImage Image;
Image.Height = vSrcImage.Height;
Image.Width = vSrcImage.Width;
Image.Data = vSrcImage.Data;
double Threshold = vVariance;
int HalfHeight = Image.Height / 2;
int HalfWidth = Image.Width / 2;
for (int i = 0; i < HalfHeight; i++)
{
for (int j = HalfWidth; j < Image.Width; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
else
Image.Data[i][j] -= Threshold;
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
for (int i = HalfHeight; i < Image.Height; i++)
{
for (int j = 0; j < HalfWidth; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
else
Image.Data[i][j] -= Threshold;
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
for (int i = HalfHeight; i < Image.Height; i++)
{
for (int j = HalfWidth; j < Image.Width; j++)
{
int Temp = vSrcImage.Data[i][j];
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
if (vSrcImage.Data[i][j] < Threshold)
Image.Data[i][j] = 0;
else
Image.Data[i][j] = Threshold;
if (Temp < 0)
Image.Data[i][j] = -Image.Data[i][j];
}
}
return Image;
}
MyImage CHarrWavelet::waveletTransform(MyImage &vSrcImage)
{
MyImage RowHandledImage = waveletRowTransform(vSrcImage);
return waveletColumnTransform(RowHandledImage);
}
MyImage CHarrWavelet::waveletRowTransform(MyImage& vSrcImage)
{
int Height = vSrcImage.Height;
int Width = vSrcImage.Width;
MyImage Image;
Image.Height = Height;
Image.Width = Width;
Image.Data.resize(Height);
for (int i = 0; i < Height; i++)
{
Image.Data[i].resize(Width);
}
_ASSERT(Width % 2 == 0);
_ASSERT(Height % 2 == 0);
int HalfWidth = Width /2;
for (int i = 0; i < Height; i++)
{
for (int k = 0; k < Width; k+=2)
{
double FirstValue = vSrcImage.Data[i][k];
double SecondValue = vSrcImage.Data[i][k + 1];
int Index = k >> 1;
Image.Data[i][Index] = (FirstValue + SecondValue) / 2;
Image.Data[i][Index+HalfWidth] = (FirstValue -SecondValue) / 2;
}
}
return Image;
}
MyImage CHarrWavelet::waveletColumnTransform(MyImage& vSrcImage)
{
int Height = vSrcImage.Height;
int Width = vSrcImage.Width;
MyImage Image;
Image.Height = Height;
Image.Width = Width;
Image.Data.resize(Height);
for (int i = 0; i < Height; i++)
{
Image.Data[i].resize(Width);
}
_ASSERT(Width % 2 == 0);
_ASSERT(Height % 2 == 0);
int HalfHeight = Height / 2;
for (int i = 0; i < Height; i+=2)
{
for (int k = 0; k < Width; k ++)
{
double FirstValue = vSrcImage.Data[i][k];
double SecondValue = vSrcImage.Data[i+1][k];
int Index = i >> 1;
Image.Data[Index][k] = (FirstValue + SecondValue) / 2;
Image.Data[Index+HalfHeight][k] = (FirstValue - SecondValue) / 2;
}
}
return Image;
}
MyImage CHarrWavelet::estiMyImageeThreshlod()
{
MyImage a;
return a;
}
MyImage CHarrWavelet::inverWaveletTransform(MyImage& vSrcImage)
{
MyImage ColumnHandledImage = inverWaveletColumnTransform(vSrcImage);
return inverWaveletRowTransform(ColumnHandledImage);
}
MyImage CHarrWavelet::inverWaveletRowTransform(MyImage& vSrcImage)
{
int Height = vSrcImage.Height;
int Width = vSrcImage.Width;
MyImage Image;
Image.Height = Height;
Image.Width = Width;
Image.Data.resize(Height);
for (int i = 0; i < Height; i++)
{
Image.Data[i].resize(Width);
}
_ASSERT(Width % 2 == 0);
_ASSERT(Height % 2 == 0);
int HalfWidth = Width / 2;
for (int i = 0; i < Height; i++)
{
for (int k = 0; k < HalfWidth; k++)
{
double FirstValue = vSrcImage.Data[i][k];
double SecondValue = vSrcImage.Data[i][k + HalfWidth];
Image.Data[i][k * 2] = FirstValue + SecondValue;
Image.Data[i][k * 2 + 1] = FirstValue - SecondValue;
}
}
return Image;
}
MyImage CHarrWavelet::inverWaveletColumnTransform(MyImage& vSrcImage)
{
int Height = vSrcImage.Height;
int Width = vSrcImage.Width;
MyImage Image;
Image.Height = Height;
Image.Width = Width;
Image.Data.resize(Height);
for (int i = 0; i < Height; i++)
{
Image.Data[i].resize(Width);
}
_ASSERT(Width % 2 == 0);
_ASSERT(Height % 2 == 0);
int HalfHeight = Height / 2;
for (int i = 0; i < HalfHeight; i++)
{
for (int k = 0; k < Width; k++)
{
double FirstValue = vSrcImage.Data[i][k];
double SecondValue = vSrcImage.Data[i + HalfHeight][k];
Image.Data[i * 2][k] = FirstValue + SecondValue ;
Image.Data[i * 2 + 1][k] = FirstValue - SecondValue;
}
}
return Image;
}
MyImage CHarrWavelet::getNextData(MyImage& vSrcImage)
{
MyImage Image;
Image.Width = vSrcImage.Width/2;
Image.Height = vSrcImage.Height/2;
Image.Data.resize(Image.Height);
for (int i = 0; i < Image.Height; i++)
{
Image.Data[i].resize(Image.Width);
}
for (int i = 0; i < Image.Height; i++)
{
for (int j = 0; j < Image.Width; j++)
{
Image.Data[i][j] = vSrcImage.Data[i][j];
}
}
return Image;
}
MyImage CHarrWavelet::update(MyImage& vNextImage,MyImage& vOriginalImage)
{
MyImage Image;
Image.Width = vOriginalImage.Width;
Image.Height = vOriginalImage.Height;
Image.Data = vOriginalImage.Data;
for (int i = 0; i < vNextImage.Height; i++)
{
for (int j = 0; j < vNextImage.Width; j++)
{
Image.Data[i][j] = vNextImage.Data[i][j];
}
}
return Image;
}
MyImage CHarrWavelet::denoiseImage(MyImage& vSrcImage, double vThreshold1, double vThreshold2,bool vIsHard)
{
MyImage FirstLevelWaveImage = waveletTransform(vSrcImage);
MyImage SecondLevelImage = getNextData(FirstLevelWaveImage);
MyImage SecondLevelWaveImage = waveletTransform(SecondLevelImage);
MyImage SecondLevelDenoiseWaveImage;
if(vIsHard)
SecondLevelDenoiseWaveImage= m_Threshold.processedWithHard(Second
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
数字图像处理基于c++和opencv的图像小波阈值去噪源码(软阈值和硬阈值处理)+代码注释+sln解决方案.zip 数字图像处理-小波去噪 预置条件: 需要配置Onencv(用于加载图片) vs2017 实现功能: 二维Harr小波变换 二维Harr小波去噪 软阈值和硬阈值处理 实现基于C++和OpenCV
资源推荐
资源详情
资源评论
收起资源包目录
数字图像处理基于c++和opencv的图像小波阈值去噪源码(软阈值和硬阈值处理)+代码注释+sln解决方案.zip (12个子文件)
说明.md 222B
.gitattributes 2KB
WaveDenoseProject
Noise.h 522B
WaveDenoseProject.vcxproj 7KB
Noise.cpp 2KB
HarrWavelet.cpp 8KB
main.cpp 3KB
WaveDenoseProject.vcxproj.filters 1KB
HarrWavelet.h 1KB
Test1.jpg 31KB
WaveDenoseProject.sln 1KB
.gitignore 4KB
共 12 条
- 1
资源评论
- 2301_774735202023-10-03感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。onnx2024-06-18不客气,感谢您对项目资源的认可和支持,欢迎下载使用,有问题请及时私信沟通,帮助答疑!
- JUST_Z12023-05-02简直是宝藏资源,实用价值很高,支持!onnx2023-09-26感谢您的支持和认可,互相学习,加油 啊
onnx
- 粉丝: 9384
- 资源: 5588
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- new_bird_c-c语言入门
- christmasTree-圣诞树html网页代码
- working-shell脚本入门——流程控制
- hadoop_install-sqoop数据导入
- ThinkCMF-mysql安装
- BigData-Notes-sqoop的安装与配置
- C语言-leetcode题解之28-implement-strstr.c
- C语言-leetcode题解之27-remove-element.c
- C语言-leetcode题解之26-remove-duplicates-from-sorted-array.c
- C语言-leetcode题解之24-swap-nodes-in-pairs.c
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功