上采样(cv::pyrUp) – zoom in 放大
pyrUp(Mat src, Mat dst, Size(src.cols2, src.rows2))
生成的图像是原图在宽与高各放大两倍
降采样 (cv::pyrDown) – zoom out 缩小
pyrDown(Mat src, Mat dst, Size(src.cols/2, src.rows/2))
生成的图像是原图在宽与高各缩小1/2
#include
#include
using namespace cv;
int main(){
//1. 加载图像和显示原图
Mat src=imread("E:/Experiment/OpenCV/Pictures/dog2.jpg");
if(src.empty()){
printf("could not load image...");
return -1;
}
namedWindow("input_windows",CV_WINDOW_AUTOSIZE);
imshow("input_windows",src);//显示图片
//2. 创建两个Mat对象来存储操作的结果,并执行采样操作
Mat dst1,dst2;
//2.1. 上采样
pyrUp(src, dst1, Size(src.cols * 2, src.rows * 2));//上采样,生成的图像是原图在宽与高各放大两倍
imshow("pyrUp", dst1);
//2.2. 下采样
pyrDown(src, dst2, Size(src.cols / 2, src.rows / 2));//降采样,生成的图像是原图在宽与高各缩小1/2
imshow("pyrDown", dst2);
//高斯不同
Mat gray_src,gblur1,gblur2,gblur3,dogImg,dogImg2,dogImg3;
cvtColor(src, gray_src, COLOR_BGR2GRAY);
GaussianBlur(gray_src, gblur1, Size(3, 3), 0, 0);
GaussianBlur(gblur1, gblur2, Size(3, 3), 0, 0);//方式一
subtract(gblur1, gblur2, dogImg, Mat());//获取 DOG ,应该要低的gblur1减高的gblur2
//将灰度图的0-255空间,转换到0-1空间(二值空间),让原本淡淡的图像变得清楚了
normalize(dogImg, dogImg, 255, 0, NORM_MINMAX);//参数:255最大值,0最小值,NORM_MINMAX 最大最小化
imshow("dogImg", dogImg);//能看到淡淡的猫的眼睛的轮廓
GaussianBlur(gray_src, gblur3, Size(5, 5), 0, 0);
subtract(gblur1, gblur3, dogImg2, Mat());//方式二
normalize(dogImg2, dogImg2, 255, 0, NORM_MINMAX);
imshow("dogImg2", dogImg2);//也能看到淡淡的猫的眼睛的轮廓
subtract(gblur2, gblur1, dogImg3, Mat());//高减低的
normalize(dogImg3, dogImg3, 255, 0, NORM_MINMAX);
imshow("dogImg3", dogImg3);
waitKey(0);
return 0;
}
1. 加载图片
2. 进行上采样(按’u’后):
3. 执行下采样(按’d’后):
4. 退出程序(按’Esc’后):
#include
#include
using namespace cv;
int main(){
//1. 加载图像和显示原图
Mat src=imread("E:/Experiment/OpenCV/Pictures/dog2.jpg");
if(src.empty()){
printf("could not load image...");
return -1;
}
namedWindow("input_windows",CV_WINDOW_AUTOSIZE);
imshow("input_windows",src);//显示图片
Mat temp,dst;
temp=src;
dst=temp;
while(true){
int c;
c = waitKey(10);
if( (char)c == 27 ){
//Esc键
break;
}
else if( (char)c == 'u' ){
pyrUp( temp, dst, Size( temp.cols*2, temp.rows*2 ) );
printf( "** Zoom In: Image x 2 \n" );
}
else if( (char)c == 'd' )
{
pyrDown( temp, dst, Size( temp.cols/2, temp.rows/2 ) );
printf( "** Zoom Out: Image / 2 \n" );
}
imshow( "output_windows", dst );
temp = dst;
}
waitKey(0);
return 0;
}
- https://blog.csdn.net/LYKymy/article/details/83153927
- https://blog.csdn.net/huanghuangjin/article/details/80958983