图像增强 数据增强

2023-10-30

目录

python opncv 数据增强 亮度:

opencv 亮度饱和度增强:

vgg19图像增强

c++ opencv 图像增强


python opncv 数据增强 亮度:

def data_augment(image, brightness):
    factor = 1.0 + random.uniform(-1.0*brightness, brightness)
    table = np.array([(i / 255.0) * factor * 255 for i in np.arange(0, 256)]).clip(0,255).astype(np.uint8)
    image = cv2.LUT(image, table)
    return image, factor

if __name__ == '__main__':
    import os
    img=cv2.imread('img/8883.jpg')

    while True:

        # image_t, beta = _distort(img)
        image_t,factor = data_augment(img,0.3)

        cv2.imshow("asdf",image_t)
        cv2.waitKey()

opencv 亮度、饱和度增强:

import random

import cv2
import numpy as np
import pandas as pd


def aug_HLS(img):
   min_v = -20
   MAX_VALUE =50
   fImg = img.astype(np.float32)
   fImg = fImg / 255.0
   # HLS空间,三个通道分别是: Hue色相、lightness明度、saturation饱和度
   # 通道0是色相、通道1是明度、通道2是饱和度
   hlsImg = cv2.cvtColor(fImg, cv2.COLOR_BGR2HLS)

   lnum = random.uniform(min_v, MAX_VALUE)
   snum = random.uniform(min_v, MAX_VALUE)
   cnum = random.uniform(min_v, MAX_VALUE)
   # print(lnum, snum, cnum)
   # 1.调整亮度饱和度(线性变换)、 2.将hlsCopy[:,:,1]和hlsCopy[:,:,2]中大于1的全部截取
   hlsImg[:, :, 1] = (1.0 + lnum / 100.0) * hlsImg[:, :, 1]
   hlsImg[:, :, 1][hlsImg[:, :, 1] > 1] = 1
   # HLS空间通道2是饱和度,对饱和度进行线性变换,且最大值在255以内,这一归一化了,所以应在1以内
   hlsImg[:, :, 2] = (1.0 + snum / 100.0) * hlsImg[:, :, 2]
   hlsImg[:, :, 2][hlsImg[:, :, 2] > 1] = 1

   # HLS2BGR
   lsImg = cv2.cvtColor(hlsImg, cv2.COLOR_HLS2BGR)
   lsImg = (lsImg * 255).astype(np.uint8)
   return lsImg

if __name__ == '__main__':

   img=cv2.imread(r'D:\data\similar\0822_1405\imgs\0822_0714-141713_20019_0_0_77.jpg')

   while True:
      img_a=aug_HLS(img)

      cv2.imshow("asdf",img)

      cv2.imshow("img-a",img_a)

      cv2.waitKey()

vgg19图像增强

vgg19,模型500多m,效果还行

https://github.com/aiff22/DPED

c++ opencv 图像增强



#include <QCoreApplication>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv/ml.h>
#include<opencv2/photo/photo.hpp>
using namespace cv;
using namespace std;
cv::Mat image_clahe;
int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 0;
void Erosion( int, void* )
{Mat dst1;
  int erosion_type;
  namedWindow( "Erosion Demo", CV_WINDOW_AUTOSIZE );
  if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
  else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
  else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
  Mat element = getStructuringElement( erosion_type,
                                       Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                                       Point( erosion_size, erosion_size ) );
  /// Apply the erosion operation
  erode( image_clahe, image_clahe, element,Point(0,0),3000 );
  fastNlMeansDenoisingColored( image_clahe, dst1, 3, 3, 7, 21 );
  imshow( "Erosion Demo", dst1);
  imwrite("/home/sukhad/Downloads/Nipun.jpg",dst1);
}
/** @function Dilation */
void Dilation( int, void* )
{
  int dilation_type;
  namedWindow( "Dilation Demo", CV_WINDOW_AUTOSIZE );
  if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
  else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
  else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
  Mat element = getStructuringElement( dilation_type,
                                       Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                                       Point( dilation_size, dilation_size ) );
  /// Apply the dilation operation
  dilate( image_clahe, image_clahe, element,Point(0,0),3000 );
  imshow( "Dilation Demo", image_clahe );
}
    int main(int argc, char** argv)
    {
        QCoreApplication a(argc, argv);
        // READ RGB color image and convert it to Lab
        cv::Mat bgr_image;
        cv::Mat lab_image;
        bgr_image=imread("051246060311637.png");
        cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);
cv::Mat dst1;
        // Extract the L channel
        std::vector<cv::Mat> lab_planes(3);
        cv::split(lab_image, lab_planes);  // now we have the L image in lab_planes[0]
        // apply the CLAHE algorithm to the L channel
        cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
        clahe->setClipLimit(4);
        cv::Mat dst;
        clahe->apply(lab_planes[0], dst);
        // Merge the the color planes back into an Lab image
        dst.copyTo(lab_planes[0]);
        cv::merge(lab_planes, lab_image);
       // convert back to RGB
       cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
       namedWindow( "image original", CV_WINDOW_AUTOSIZE );
       namedWindow( "image CLAHE", CV_WINDOW_AUTOSIZE );
       // display the results  (you might also want to see lab_planes[0] before and after).
       Erosion( 0, 0 );
         Dilation( 0, 0 );
         imshow("image original", bgr_image);
  imshow("image CLAHE", image_clahe);
       return a.exec();
}
//#include <iostream>
//#include <iomanip>
//#include <math.h>
//#include <ctime>
//void checkTripletASM(float* aptr,float* bptr,float* cptr,int& o)
//{
//    _asm {
//        push eax
//            push ebx
//            mov eax, aptr
//            mov ebx, bptr
//            movaps xmm0, [eax]
//            movaps xmm1, [ebx]
//            movaps xmm7, xmm0
//            mulps xmm7, xmm0
//            movaps xmm2, xmm7
//            movaps xmm7, xmm1
//            mulps xmm7, xmm1
//            movaps xmm3, xmm7
//            movaps xmm4, xmm2
//            addps xmm4, xmm3
//            movaps xmm5, xmm4
//            sqrtps xmm5, xmm5
//            roundps xmm5, xmm5, 1
//            mulps xmm5, xmm5
//            subps xmm5, xmm4
//            mov eax, cptr
//            movaps[eax], xmm5
//            pop ebx
//            pop eax
//    }
//    for (int i = 0; i < 4;i++)
//        if (*(cptr + i) == 0.0)
//        {
//            o++;
//            //std::cout << *(aptr + i) << " " << *(bptr + i) << " " << *(aptr + i) * *(aptr + i) +
//            //*(bptr + i) * *(bptr + i) << std::endl;
//        }
//}
//void checkTripletC(float* aptr, float* bptr, float* cptr, int& o)
//{
//    for (int i = 0 ; i < 4;i++)
//    {
//        float a = aptr[i] * aptr[i] + bptr[i] * bptr[i];
//        if (sqrt(a) == round(sqrt(a)))
//        {
//            o++;
//        //std::cout << aptr[i] << " " << bptr[i] <<" "<<  a << std::endl;
//        }
//    }
//}
//float Experiment( void(*fun)(float*, float*, float*, int&), int& countas,int pr)
//{
//    int n = pr;
//    __declspec(align(16)) float pa[4] = { 1,1,6,1 };
//    __declspec(align(16)) float pb[4] = { 4096,1,8,1 };
//    __declspec(align(16)) float ts[4] = { 0,0,0,0 };
//    float* aptr = &pa[0];
//    float* bptr = &pb[0];
//    float* cptr = &ts[0];
//    int c = 0;
//    int o = 0;
//    std::clock_t b = std::clock();
//    for (int i = 1; i <= n; i++)
//        for (int j = i; j <= n;j++)
//        {
//            pa[c] = i; pb[c] = j; c++;
//            if (c == 4)
//            {
//                c = 0;
//                fun(aptr, bptr, cptr, o);
//            }
//        }
//    std::clock_t end = std::clock();
//    float ats = (float)(end - b) / CLOCKS_PER_SEC ;
//    countas = o;
//    return ats;
//}
//int main()
//{
//    int n = 100;
//    int pr = 2000;
//    float m = 0;
//    void(*fun)(float*,float*,float*,int&);
//    fun = &checkTripletASM;
//    int c = 0;
//    std::cout << "RUNS: " << n << " PER RUN: " << pr << std::endl;
//    std::cout << "TEST BEGINS! \n";
//    for (int i = 0; i < n;i++)
//        m += Experiment(fun,c,pr);
//    std::cout <<"SSE/FLOAT TIME: "<< m / (float)n << " ENTRYS: " << c << std::endl;
//    m = 0;
//    fun = &checkTripletC;
//    for (int i = 0; i < n;i++)
//        m += Experiment(fun,c,pr);
//    std::cout << "C++/FLOAT TIME: " << m / (float)n << " ENTRYS: " << c << std::endl;
//    std::cout << "TEST END!";
//    std::cin.ignore();
//}
目标效果如下,但是本demo好像达不到
 <QCoreApplication>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv/ml.h>
#include<opencv2/photo/photo.hpp>
using namespace cv;
using namespace std;
cv::Mat image_clahe;
int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 0;
void Erosion( int, void* )
{Mat dst1;
  int erosion_type;
  namedWindow( "Erosion Demo", CV_WINDOW_AUTOSIZE );
  if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
  else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
  else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
  Mat element = getStructuringElement( erosion_type,
                                       Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                                       Point( erosion_size, erosion_size ) );
  /// Apply the erosion operation
  erode( image_clahe, image_clahe, element,Point(0,0),3000 );
  fastNlMeansDenoisingColored( image_clahe, dst1, 3, 3, 7, 21 );
  imshow( "Erosion Demo", dst1);
  imwrite("/home/sukhad/Downloads/Nipun.jpg",dst1);
}
/** @function Dilation */
void Dilation( int, void* )
{
  int dilation_type;
  namedWindow( "Dilation Demo", CV_WINDOW_AUTOSIZE );
  if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
  else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
  else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
  Mat element = getStructuringElement( dilation_type,
                                       Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                                       Point( dilation_size, dilation_size ) );
  /// Apply the dilation operation
  dilate( image_clahe, image_clahe, element,Point(0,0),3000 );
  imshow( "Dilation Demo", image_clahe );
}
    int main(int argc, char** argv)
    {
        QCoreApplication a(argc, argv);
        // READ RGB color image and convert it to Lab
        cv::Mat bgr_image;
        cv::Mat lab_image;
        bgr_image=imread("051246060311637.png");
        cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);
cv::Mat dst1;
        // Extract the L channel
        std::vector<cv::Mat> lab_planes(3);
        cv::split(lab_image, lab_planes);  // now we have the L image in lab_planes[0]
        // apply the CLAHE algorithm to the L channel
        cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
        clahe->setClipLimit(4);
        cv::Mat dst;
        clahe->apply(lab_planes[0], dst);
        // Merge the the color planes back into an Lab image
        dst.copyTo(lab_planes[0]);
        cv::merge(lab_planes, lab_image);
       // convert back to RGB
       cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
       namedWindow( "image original", CV_WINDOW_AUTOSIZE );
       namedWindow( "image CLAHE", CV_WINDOW_AUTOSIZE );
       // display the results  (you might also want to see lab_planes[0] before and after).
       Erosion( 0, 0 );
         Dilation( 0, 0 );
         imshow("image original", bgr_image);
  imshow("image CLAHE", image_clahe);
       return a.exec();
}
//#include <iostream>
//#include <iomanip>
//#include <math.h>
//#include <ctime>
//void checkTripletASM(float* aptr,float* bptr,float* cptr,int& o)
//{
//    _asm {
//        push eax
//            push ebx
//            mov eax, aptr
//            mov ebx, bptr
//            movaps xmm0, [eax]
//            movaps xmm1, [ebx]
//            movaps xmm7, xmm0
//            mulps xmm7, xmm0
//            movaps xmm2, xmm7
//            movaps xmm7, xmm1
//            mulps xmm7, xmm1
//            movaps xmm3, xmm7
//            movaps xmm4, xmm2
//            addps xmm4, xmm3
//            movaps xmm5, xmm4
//            sqrtps xmm5, xmm5
//            roundps xmm5, xmm5, 1
//            mulps xmm5, xmm5
//            subps xmm5, xmm4
//            mov eax, cptr
//            movaps[eax], xmm5
//            pop ebx
//            pop eax
//    }
//    for (int i = 0; i < 4;i++)
//        if (*(cptr + i) == 0.0)
//        {
//            o++;
//            //std::cout << *(aptr + i) << " " << *(bptr + i) << " " << *(aptr + i) * *(aptr + i) +
//            //*(bptr + i) * *(bptr + i) << std::endl;
//        }
//}
//void checkTripletC(float* aptr, float* bptr, float* cptr, int& o)
//{
//    for (int i = 0 ; i < 4;i++)
//    {
//        float a = aptr[i] * aptr[i] + bptr[i] * bptr[i];
//        if (sqrt(a) == round(sqrt(a)))
//        {
//            o++;
//        //std::cout << aptr[i] << " " << bptr[i] <<" "<<  a << std::endl;
//        }
//    }
//}
//float Experiment( void(*fun)(float*, float*, float*, int&), int& countas,int pr)
//{
//    int n = pr;
//    __declspec(align(16)) float pa[4] = { 1,1,6,1 };
//    __declspec(align(16)) float pb[4] = { 4096,1,8,1 };
//    __declspec(align(16)) float ts[4] = { 0,0,0,0 };
//    float* aptr = &pa[0];
//    float* bptr = &pb[0];
//    float* cptr = &ts[0];
//    int c = 0;
//    int o = 0;
//    std::clock_t b = std::clock();
//    for (int i = 1; i <= n; i++)
//        for (int j = i; j <= n;j++)
//        {
//            pa[c] = i; pb[c] = j; c++;
//            if (c == 4)
//            {
//                c = 0;
//                fun(aptr, bptr, cptr, o);
//            }
//        }
//    std::clock_t end = std::clock();
//    float ats = (float)(end - b) / CLOCKS_PER_SEC ;
//    countas = o;
//    return ats;
//}
//int main()
//{
//    int n = 100;
//    int pr = 2000;
//    float m = 0;
//    void(*fun)(float*,float*,float*,int&);
//    fun = &checkTripletASM;
//    int c = 0;
//    std::cout << "RUNS: " << n << " PER RUN: " << pr << std::endl;
//    std::cout << "TEST BEGINS! \n";
//    for (int i = 0; i < n;i++)
//        m += Experiment(fun,c,pr);
//    std::cout <<"SSE/FLOAT TIME: "<< m / (float)n << " ENTRYS: " << c << std::endl;
//    m = 0;
//    fun = &checkTripletC;
//    for (int i = 0; i < n;i++)
//        m += Experiment(fun,c,pr);
//    std::cout << "C++/FLOAT TIME: " << m / (float)n << " ENTRYS: " << c << std::endl;
//    std::cout << "TEST END!";
//    std::cin.ignore();
//}
目标效果如下,但是本demo好像达不到
 

       

       

       

项目地址:https://github.com/sukhad-app/under-water-image-enhancement

这个效果也一般:

http://download.csdn.net/download/mashang666/9555191

http://download.csdn.net/detail/dbc12345666/8092531,这个图像增强后效果:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

图像增强 数据增强 的相关文章

随机推荐

  • VS2008中的ncb、pdb文件分析

    NCB是 No Compile Browser 的缩写 称为 无编译浏览文件 其中存放了供ClassView WizardBar和Component Gallery使用的信息 由VC开发环境自动生成 工程拷来拷去都会生成新的信息以适应新的环
  • 【python】CodingGames Shadows of the Knight - Episode 1

    CodingGames 之 蝙蝠侠救人 描述 你是蝙蝠侠 你将通过使用你的抓斗枪从一个窗口跳到另一个窗口来寻找给定建筑物上的人质 您的目标是跳到人质所在的窗口以解除炸弹的武装 不幸的是 在炸弹爆炸之前你的跳跃次数是有限的 在每次跳跃之前 热
  • 经验:在Maven项目中,打包时指定 main class 的配置(亲测有效)

    Maven打包的时候 是不是经常会出现 没有主清单属性 的报错 以下的配置 放在 pom xml 最后的 lt build gt 中 就能自定义main函数所在的类 然后打包了
  • 谷歌、OpenAI等警告:BERT、GPT-3等大型语言模型都有一个重大缺陷,很危险...

    2020 12 17 00 14 54 作者 青暮 语言模型已经变得越来越强大 可胜任的任务也越来越多 这些仅仅以预测句子中下一个单词进行训练的模型 已经在诸如问答 翻译等应用程序中取得了突破性的进展 前段时间在社交媒体上活跃异常的GPT
  • 《消息队列高手课》主题和队列有什么区别?

    如果你研究过超过一种消息队列产品 你可能已经发现 每种消息队列都有自己的一套消息模型 像队列 Queue 主题 Topic 或是分区 Partition 这些名词概念 在每个消息队列模型中都会涉及一些 含义还不太一样 为什么出现这种情况呢
  • Service Intent must be explicit的解决方法

    http blog csdn net shenzhonglaoxu article details 42708723 java view plain copy final Intent intent new Intent intent se
  • jeesite框架中获取登入用户的登入名

    jeesite框架中获取登入用户的登入名 UserUtils getUserName
  • 17 张图实战 + 理清 K8S 网络排错思路,硬核!

    作者 Cylon出处 https u kubeinfo cn R35JNc Overview 本文将引入一个思路 在 Kubernetes 集群发生网络异常时如何排查 文章将引入 Kubernetes 集群中网络排查的思路 包含网络异常模型
  • 算法笔记之旅——问题B:出租车费

    题目描述 某市出租车计价规则如下 起步4公里10元 即使你的行程没超过4公里 接下来的4公里 每公里2元 之后每公里2 4元 行程的最后一段即使不到1公里 也当作1公里计费 一个乘客可以根据行程公里数合理安排坐车方式来使自己的打车费最小 例
  • 空间误差分析:统一的应用导向处理(Matlab代码实现)

    个人主页 研学社的博客 欢迎来到本博客 博主优势 博客内容尽量做到思维缜密 逻辑清晰 为了方便读者 座右铭 行百里者 半于九十 本文目录如下 目录 1 概述 2 运行结果 3 参考文献 4 Matlab代码实现 1 概述 本文关
  • SVN软件中patch的的运用以及patch介绍

    什么是patch patch就是补丁 在程序中就是和原来相比有差异的部分 生活中常见的就是程序升级 假设我们用手机下载某个软件显示是100M大小 第一次安装时就需要下载100M大小的安装包 当安装完成后 后续会收到软件升级的提醒 升级包可能
  • Vuforia提高识别图星级

    本文转载自http blog csdn net unity3d xyz article details 50638007 高通的识别图上传到后台以后我们可以看有星级评定 星值最大为5星 星值越大有以下好处 1 识别图越容易识别 2 识别出来
  • 从零开始的RVOS: Referring Video Object Segmentation

    最近新接触到一个与VOS相关的任务 叫做Referring VOS 该任务基于文本描述对视频中特定目标进行分割 是一个新兴的跨模态CV任务 数据集 1 静态推断图像分割数据集 虽然RVOS是视频任务 但根据以往的经验和相关文章的方法 可以使
  • 水文模型有哪些?SWAT模型、VIC模型、HEC模型、HSPF模型、HYPE模型、SWMM模型、FVCOM模型、Delft3D模型等应用

    目录 从小白到精通SWAT模型学习建模方法 实例应用 高级进阶 R VIC模型融合实践技术应用及未来气候变化模型预测 HEC RAS一维 二维建模方法及实践技术应用 HEC HMS水文模型实践技术应用 HSPF 模型应用 HYPE分布式水文
  • Service的两种启动方式

    在Android开发的过程中 Service是一个非常重要的组件 它的生命周期里面有几个特别重要的方法 Service的生命周期 onCreate 当服务创建的时候调用 onStartCommand startServcie的时候会调用这个
  • RFID作业(第三次)

    1 通信系统中为什么要进行编码和解码 常见的编码方法有哪些 信源编码是指将模拟信号转换成数字信号 或将数字信号编码成更合适传输的数字信号 换句话来说 通信系统编码和解码是为了让信号更适合传输 常见的编码方法有1 反向不归零编码 2 曼彻斯特
  • ListView的复用问题,点击条目变色.不复用

    主要的是3个类 包含activity application 和一个adpter 内部的细节在代码中都有详细的注释 可以参考 application public class MyApplication extends Applicatio
  • PyQt5学习笔记16----PyQt信号和槽传递额外参数

    使用Pyqt编程过程中 经常会遇到给槽函数传递额外参数的情况 但是信号 槽机制只是指定信号如何连接到槽 信号定义的参数被传递给槽 而额外的参数 用户定义 不能直接传递 而传递额外参数又是很有用处 你可能使用一个槽处理多个组件的信号 有时要传
  • GIT实战篇,教你如何使用GIT可视化工具

    系列文章目录 手把手教你安装Git 萌新迈向专业的必备一步 GIT命令只会抄却不理解 看完原理才能事半功倍 快速上手GIT命令 现学也能登堂入室 GIT实战篇 教你如何使用GIT可视化工具 系列文章目录 一 GIT有哪些常用工具 1 Git
  • 图像增强 数据增强

    目录 python opncv 数据增强 亮度 opencv 亮度饱和度增强 vgg19图像增强 c opencv 图像增强 python opncv 数据增强 亮度 def data augment image brightness fa