目录

cv::resize()

Image Pyramids

pyrDown()

buildPyramid()

pyrUp()

The Laplacian pyramid


cv::resize()

void cv::resize(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size dsize, // New size
double fx = 0, // x-rescale
double fy = 0, // y-rescale
int interpolation = CV::INTER_LINEAR // interpolation method
);

We can specify the size of the output image in two ways. One way is to use absolute
sizing; in this case, the dsize argument directly sets the size we would like the result
image dst to be. The other option is to use relative sizing; in this case, we set dsize to
cv::Size(0,0), and set fx and fy to the scale factors we would like to apply to the xand y-axes, respectively.1 The last argument is the interpolation method, which
defaults to linear interpolation.

Image Pyramids

Image pyramids [Adelson84] are heavily used in a wide variety of vision applications.
An image pyramid is a collection of images—all arising from a single original image
—that are successively downsampled until some desired stopping point is reached.
(This stopping point could be a single-pixel image!)

There are two kinds of image pyramids that arise often in the literature and in appli‐
cations: the Gaussian [Rosenfeld80] and Laplacian [Burt83] pyramids [Adelson84].
The Gaussian pyramid is used to downsample images, and the Laplacian pyramid
(discussed shortly) is required when we want to reconstruct an upsampled image
from an image lower in the pyramid.

pyrDown()

void cv::pyrDown(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
const cv::Size& dstsize = cv::Size() // Output image size
);

The cv::pyrDown() method will do exactly this for us if we leave the destination size
argument dstsize set to its default value of cv::Size(). To be a little more specific,
the default size of the output image is ( (src.cols+1)/2, (src.rows+1)/2 ).4
Alternatively, we can supply a dstsize, which will indicate the size we would like for
the output image; dstsize, however, must obey some very strict constraints. Specifi‐
cally

| dstsize.width*2 - src.cols | ≤ 2
| dstsize.height *2 - src.rows | ≤ 2
这个值会在图像长宽一半的附件,并且可以用的值范围很小,所以Size两个值自己输入想要的大小时要注意,不然程序会出错

#include <opencv2/opencv.hpp>using namespace cv;void copyPixel(const Mat& src, Mat& dst)
{for (size_t i = 0; i < src.rows; i++){for (size_t j = 0; j < src.cols; j++){dst.at<Vec3b>(i, j)[0] = src.at<Vec3b>(i, j)[0];  //蓝色通道dst.at<Vec3b>(i, j)[1] = src.at<Vec3b>(i, j)[1];  //绿色通道dst.at<Vec3b>(i, j)[2] = src.at<Vec3b>(i, j)[2];  //红是通道}}
}int main()
{Mat src = imread("NWPULB.jpg", IMREAD_COLOR);int width = src.cols / 6;int height = src.rows / 6;//resize(src, src, Size(width, height));resize(src, src, Size(0, 0), 0.15, 0.15);Mat pyrSrc;//pyrDown(src, pyrSrc, Size(400, 300));pyrDown(src, pyrSrc, Size(0, 0));Mat image = Mat(Size(2*width, height), src.type());namedWindow("image", 1);//imshow("images", src);if (src.empty()){std::cout << "Could not open or find the image!\n" << std::endl;return EXIT_FAILURE;}Mat imageWarp = Mat(Size(src.cols, src.rows), src.type());Mat warp = (Mat_<float>(2, 3) << 1, 0, src.cols-1, 0, 1, 0);//warpAffine(src, imageWarp, warp, Size(2 * src.cols, src.rows));warpAffine(pyrSrc, imageWarp, warp, Size(2 * src.cols, src.rows));//imshow("image", imageWarp);copyPixel(src, imageWarp);imshow("image", imageWarp);waitKey();destroyWindow("image");return 0;
}

(4000,5328)-------resize后------》(600, 799)------>现在计算pyDown时自己输入长宽的值

393.5<= width <= 400.5

299<=height <= 301     所以自己输入时值并不可以“随便取”

This restriction means that the destination image is very close to half the size of the
source image. The dstsize argument is used only for handling somewhat esoteric
cases in which very tight control is needed on how the pyramid is constructed.

buildPyramid()

It is a relatively common situation that you have an image and wish to build a
sequence of new images that are each downscaled from their predecessor. The func‐
tion cv::buildPyramid() creates such a stack of images for you in a single call

void cv::buildPyramid(
cv::InputArray src, // Input image
cv::OutputArrayOfArrays dst, // Output images from pyramid
int maxlevel // Number of pyramid levels
);

The argument src is the source image. The argument dst is of a somewhat unusuallooking type cv::OutputArrayOfArrays, but you can think of this as just being an
STL vector<> or objects of type cv::OutputArray. The most common example of this would be vector<cv::Mat>. The argument maxlevel indicates how many pyramid levels are to be constructed

#include <opencv2/opencv.hpp>
#include <algorithm>
#pragma warning(disable:4996) using namespace cv;
using namespace std;void copyPixel(const Mat& src, Mat& dst)
{for (size_t i = 0; i < src.rows; i++){for (size_t j = 0; j < src.cols; j++){dst.at<Vec3b>(i, j)[0] = src.at<Vec3b>(i, j)[0];  //蓝色通道dst.at<Vec3b>(i, j)[1] = src.at<Vec3b>(i, j)[1];  //绿色通道dst.at<Vec3b>(i, j)[2] = src.at<Vec3b>(i, j)[2];  //红是通道}}
}int main()
{Mat src = imread("NWPULB.jpg", IMREAD_COLOR);if (src.empty()){std::cout << "Could not open or find the image!\n" << std::endl;return EXIT_FAILURE;}int width = src.cols / 6;int height = src.rows / 6;//resize(src, src, Size(width, height));resize(src, src, Size(0, 0), 0.15, 0.15);Mat pyrSrc;//pyrDown(src, pyrSrc, Size(400, 300));//pyrDown(src, pyrSrc, Size(0, 0));Mat image = Mat(Size(2 * width, height), src.type());namedWindow("image", 1);//imshow("images", src);vector<Mat> buildPyts;buildPyramid(src, buildPyts, 4);Mat imageWarp = Mat(Size(src.cols, src.rows), src.type());Mat warp;char* name = new char;for (size_t i = 0; i < buildPyts.size(); i++){warp = (Mat_<float>(2, 3) << 1, 0, src.cols + i*50, 0, 1, 0);warpAffine(buildPyts[4-i], imageWarp, warp, Size(2 * src.cols, src.rows));sprintf(name, "pyts%d", i);imshow(name, buildPyts[i]);}copyPixel(src, imageWarp);imshow("image", imageWarp);waitKey();destroyWindow("image");return 0;
}

In practice, you will often want a pyramid with a finer logarithmic
scaling than factors of two. One way to achieve this is to simply call
cv::resize() yourself as many times as needed for whatever scale
factor you want to use—but this can be quite slow. An alternative
(for some common scale factors) is to call cv::resize() only once
for each interleaved set of images you want, and then call
cv::buildPyramid() on each of those resized “bases.” You can
then interleave these results together for one large, finer-grained
pyramid. Figure 11-1 (right) shows an example in which two pyra‐
mids are generated. The original image is first rescaled by a factor
of 2, and then cv::buildPyramid() is called on that one image to
make a second pyramid of four intermediate images. Once com‐
bined with the original pyramid, the result is a finer pyramid with a
scale factor of 2 across the entire pyramid.

pyrUp()

Analogous to cv::PyrDown(), if dstsize is set to its default value of cv::Size(), the
resulting image will be exactly twice the size (in each dimension) as src. Again, we
can supply a dstsize that will indicate the size we would like for the output image
dstsize, but it must again obey some very strict constraints. Specifically:

| dstsize.width*2 - src.cols | ≤ (dstsize.width%2)
| dstsize.height *2 - src.rows | ≤ (dstsize.height %2)

The Laplacian pyramid

We noted previously that the operator cv::pyrUp() is not the inverse of cv::pyr
Down(). This should be evident because cv::pyrDown() is an operator that loses
information. In order to restore the original (higher-resolution) image, we would
require access to the information that was discarded by the downsampling process.
This data forms the Laplacian pyramid.

The Gaussian and Laplacian pyramids are shown diagrammatically in Figure 11-2,
which also shows the inverse process for recovering the original image from the sub‐
images. Note how the Laplacian is really an approximation that uses the difference of
Gaussians, as revealed in the preceding equation and diagrammed in the figure.

2020-12-28 learning opencv3: 十一:resize, pyrDown, buildPyramid, pyrUp相关推荐

  1. 如何将谷歌浏览器的背景色(包括显示的网站界面等)全部调为黑色?2020.12.28

    (请先看置顶博文)https://blog.csdn.net/GenuineMonster/article/details/104495419 因为电脑显示器正对窗户的原因,平时为了透气通风不能使用遮 ...

  2. 458、Java框架112 -【MyBatis - 一级缓存、二级缓存】 2020.12.28

    目录 0.一级缓存 1.在一个Session里查相同id的数据 2.在不同Session里查相同id的数据 3.二级缓存 4.基于前一个知识点 5.观察无二级缓存 6.启动二级缓存 7.在Catego ...

  3. 2020.12.28 ps临摹

    欢迎观看阿贝贝啊的今日成果 今天临摹了一张书本上的作业 涉及的工具不是很多,都是基础小玩意. 需要素材可私聊. 感谢观看阿贝贝啊的今日划水 日常 .

  4. 复制列表 -copy() 2020.12.28

    复制列表 -copy() 基本格式 案例演示 查看结果

  5. (十一:2020.08.28)CVPR 2017 追踪之论文纲要(译)

    CVPR 2017 追踪之论文纲要(修正于2020.08.28) 讲在前面 论文目录 讲在前面 论坛很多博客都对论文做了总结和分类,但就医学领域而言,对这些论文的筛选信息显然需要更加精细的把控,所以自 ...

  6. 十一、“由专入分易,由分入专难。”(2020.12.18)

    十一."由专入分易,由分入专难."(2020.12.18)

  7. English Learning - Day22 作业打卡 2022.12.28 周三

    English Learning - Day22 作业打卡 2022.12.28 周三 引言 1. 否认这一点就是闭眼不看事实. 2. 他承认拿了手表. 3. 考驾照前我还得再练练. 4. 没有你陪伴 ...

  8. 2020.12.21-12.28 人工智能行业每周技术动态

    本周是2020年的最后一周,还有3天,2020年就将画上句号. 这一年的计划,大家都完成了吗? 因为疫情的原因,很多人都感觉时间太短,一晃就到了年末,又到了为新的一年做规划的时间了. 大白也在反思,这 ...

  9. m_Orchestrate learning system---三十一、模板和需求的关系

    m_Orchestrate learning system---三十一.模板和需求的关系 一.总结 一句话总结:模板为了适应广大用户,有很多功能样式,但是,你需要的只是部分,所以删掉不需要的,如果有需 ...

  10. (十四:2020.08.28)CVPR 2014 追踪之论文纲要(译)

    CVPR 2020 追踪之论文纲要(修正于2020.08.28) 讲在前面 论文目录 讲在前面 论坛很多博客都对论文做了总结和分类,但就医学领域而言,对这些论文的筛选信息显然需要更加精细的把控,所以自 ...

最新文章

  1. 【 C 】在单链表中插入一个新节点的尝试(一)
  2. “load”: 不是“torch::jit”的成员
  3. C++条件编译:#ifdef
  4. MySQL数据库基础(五)——SQL查询
  5. treeview找到节点并展开_我们从100个经典韩剧中,找到8个「神套路」,这样写抖音剧本个个都是爆款!...
  6. 组策略批量更改固定IP为自动获取
  7. 微信公众平台高级群发接口
  8. 吴恩达机器学习课后编程作业第二课解析:logistic regression
  9. 法大大“实槌”获评《互联网周刊》“2019年度特别创新TOP50”
  10. 基于格的密码与SABER
  11. Nginx 静态压缩/缓存
  12. 戴尔游匣G15怎么样?真实体验不翻车
  13. 双堆1.数据流的中位数
  14. 淘宝批量下载图片方法
  15. Mysterious Bacteria(唯一分解定理)
  16. 文档级机器翻译综述:A Survey on Document-level Machine Translation: Methods and Evaluation
  17. ADONIS、ANOSIM、Mangel_test、MRPP
  18. python tus股票数据分析_使用Python进行快速复盘[1]: 数据获取与整理
  19. R语言解读自回归模型
  20. 全功能好用管道应力CAESAR II 2014 v7.00 WinXP_7-ISO 1DVD管道设计应力分析软件

热门文章

  1. 预知昨天事情不顺,果然碰到两个
  2. Visitor(访问者)
  3. python可变参数_Python学习之路:函数传递可变参数与不可变参数,每天学一点点...
  4. 网博士自助建站系统_自助建站系统软件不一样的建站方式
  5. 计算机cmd复制粘贴指令,win7系统使用CMD命令复制和删除文件夹的方法
  6. linux更换内核后无法上网,ubuntu 系统升级内核版本后网络不能正常启动问题
  7. python collections模块_python collections模块
  8. 人眼分辨 PPI_1080P=2K,分辨率≠清晰度?关于显示器大多数人都错了
  9. Cygwin下cscope的配置
  10. gcc编译与vc编译器区别