• 图像处理基本算法


    使用openCV进行图像处理,总感觉并不能真正的理解图像处理的核心内容,因此我感觉对图像处理的理解才是关键。

    基本的反色操作,主要是了解OpenCV对图像数据的操作方式:指针

    如下:

    unsigned char * ptr;//定义指针
    for(int i = 0 ;i < img->height;i++){
    ptr= (unsigned char*)img->imageData+ i*img->widthStep;//根据偏移获取数据
    for(int j = 0 ; j< img->width; j++){
    *(ptr+3*j) -= 20;
    *(ptr + 3* j+1) -= 20;
    *(ptr + 3*j +2) -= 20;
    }
    }

    同时注意对图像真彩和灰度的判定:

    image->nChannels == 3 真彩

    image->nChannels == 1 灰度

    #include<cv.h>
    #include<highgui.h>
    
    int main(){
    	IplImage * image;
    	image = cvLoadImage("E:\\image\\breast.tif",1);
    	cvNamedWindow("image",CV_WINDOW_AUTOSIZE);
    	cvSaveImage("E:\\image\\breast.jpg",image,0);
    	cvShowImage("image",image);
    	cvWaitKey(0);
    	unsigned char * ptr;
    	if(image->nChannels == 3){
    	for(int i = 0 ; i < image->height;i++){
    		ptr = (unsigned char *)image->imageData + i*image->widthStep; 
    		for(int j = 0; j< image->width;j++){
    			*(ptr + 3*j) = 255 - (*(ptr +3*j)); 
    			*(ptr + 3*j +1) = 255 - (*(ptr +3*j+1));
    			*(ptr + 3*j+2) = 255 - (*(ptr +3*j+2));
    		}
    	}
    	}
    
    	else if(image->nChannels == 1){
    		for(int i = 0 ; i < image->height;i++){
    			ptr = (unsigned char *)image->imageData + i*image->widthStep; 
    			for(int j = 0; j< image->width;j++){
    				*(ptr + j) = 255 - (*(ptr +j)); 
    			}
    		}
    
    	}
    	cvShowImage("image",image);
    	cvWaitKey(0);
    	cvSaveImage("E:\\image\\breast2.jpg",image,0);
    	return 0;
    }




  • 相关阅读:
    codeforces 814B An express train to reveries
    codeforces 814A An abandoned sentiment from past
    codeforces 785D D. Anton and School
    codeforces 785C Anton and Fairy Tale
    codeforces 791C Bear and Different Names
    AOP详解
    Spring集成JUnit测试
    Spring整合web开发
    IOC装配Bean(注解方式)
    IOC装配Bean(XML方式)
  • 原文地址:https://www.cnblogs.com/libing64/p/2878741.html
Copyright © 2020-2023  润新知