没有合适的资源?快使用搜索试试~ 我知道了~
灰度图像自适应插值(可扩展到RGB彩图)
3星 · 超过75%的资源 需积分: 16 15 下载量 60 浏览量
2013-02-14
15:02:30
上传
评论 1
收藏 7KB TXT 举报
温馨提示
试读
8页
基于VS2010和OpenCV2.4.3环境的灰度图像自适应插值,本人根据自适应插值放大的算法编写并运行通过,理论上比最邻域插值,双线性插值,双三次差值效果要好,看了下效果,区别不明显,欢迎纠错批评。本人QQ:841962887
资源推荐
资源详情
资源评论
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include "stdio.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <windows.h>
using namespace std;
using namespace cv;
int scale=2;
void main()
{
IplImage* original=cvLoadImage("D:\\images\\blurred_sign3.jpg",0);
CvSize result_size; // define a 2-dimensional rectangular matrix that has a certain size
result_size.height=(int)(original->height*scale);
result_size.width=(int)(original->width*scale);
IplImage* result=cvCreateImage(result_size,original->depth, 1); //create a image that is 4 times as the original one
int step_original=original->widthStep; //initialize before invite the pixels
int step_result=result->widthStep;
uchar* data_original=(uchar*)original->imageData;
uchar* data_result=(uchar*)result->imageData;
double startime = (double)getTickCount(); // set the beginning time
for (int i=0;i<result->height;i++)
#include <cxcore.h>
#include <highgui.h>
#include "stdio.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <windows.h>
using namespace std;
using namespace cv;
int scale=2;
void main()
{
IplImage* original=cvLoadImage("D:\\images\\blurred_sign3.jpg",0);
CvSize result_size; // define a 2-dimensional rectangular matrix that has a certain size
result_size.height=(int)(original->height*scale);
result_size.width=(int)(original->width*scale);
IplImage* result=cvCreateImage(result_size,original->depth, 1); //create a image that is 4 times as the original one
int step_original=original->widthStep; //initialize before invite the pixels
int step_result=result->widthStep;
uchar* data_original=(uchar*)original->imageData;
uchar* data_result=(uchar*)result->imageData;
double startime = (double)getTickCount(); // set the beginning time
for (int i=0;i<result->height;i++)
{ // initialize the result image with all the pixel values being 0
for(int j=0;j<result->width;j++)
{
data_result[i*step_result+j]=0; // data_result[i*step_result+j] means the pixel value of [i,j]
}
}
for (int i=0;i<original->height;i++) // assign pixel values(in the original image) for result-image
{
for(int j=0;j<original->width;j++)
{
int ii=scale*i; int jj=scale*j;
data_result[ii*step_result+jj]=data_original[i*step_original+j]; //original[i,j] corresponds to result[2i,2j]
}
}
// as for the first situation: odd-number pixels //
for (int i=1;i<result->height-2;i=i+2)
{
for(int j=1;j<result->width-2;j=j+2)
{
int T1=10, T2=20, T3=50; // set the threshold to be used
int a=data_result[(i-1)*step_result+(j-1)]; //assign the neighborhood values to a,b,c,d
int b=data_result[(i-1)*step_result+(j+1)];
int c=data_result[(i+1)*step_result+(j-1)];
int d=data_result[(i+1)*step_result+(j+1)];
// talk about every situation to operate the adaptive interpolation//
if (abs(a-b)<T1 && abs(a-c)<T1 && abs(a-d)<T1 && abs(b-c)<T1 && abs(b-d)<T1 && abs(c-d)<T1)
{
for(int j=0;j<result->width;j++)
{
data_result[i*step_result+j]=0; // data_result[i*step_result+j] means the pixel value of [i,j]
}
}
for (int i=0;i<original->height;i++) // assign pixel values(in the original image) for result-image
{
for(int j=0;j<original->width;j++)
{
int ii=scale*i; int jj=scale*j;
data_result[ii*step_result+jj]=data_original[i*step_original+j]; //original[i,j] corresponds to result[2i,2j]
}
}
// as for the first situation: odd-number pixels //
for (int i=1;i<result->height-2;i=i+2)
{
for(int j=1;j<result->width-2;j=j+2)
{
int T1=10, T2=20, T3=50; // set the threshold to be used
int a=data_result[(i-1)*step_result+(j-1)]; //assign the neighborhood values to a,b,c,d
int b=data_result[(i-1)*step_result+(j+1)];
int c=data_result[(i+1)*step_result+(j-1)];
int d=data_result[(i+1)*step_result+(j+1)];
// talk about every situation to operate the adaptive interpolation//
if (abs(a-b)<T1 && abs(a-c)<T1 && abs(a-d)<T1 && abs(b-c)<T1 && abs(b-d)<T1 && abs(c-d)<T1)
{
剩余7页未读,继续阅读
资源评论
- abc8k8k2014-08-07编程实现效果不是特别突出。
kingfc
- 粉丝: 4
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功