本文介绍了使用opencv放大图片像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main(int argc, char** argv){
cv::Mat gray;
cv::Mat resize;
cv::Mat big;
cv::cvtColor(src, gray, CV_BGR2GRAY);
cv::resize(gray, resize, cv::Size(src.rows/2, src.cols/2));
cv::resize(resize, big, cv::Size(src.rows, src.cols));
cv::Mat clone(resize.rows, resize.cols, CV_8U);

for(int y=0;y<resize.rows;y++){
       for(int x=0;x<resize.cols;x++){
           clone.at<uchar>(y,x) = resize.at<uchar>(y,x);

                               }
                                 }
            cv::imshow("clone", clone);

我写了我的代码,我有两个问题
1)如何放大1像素变成4像素?并显示它们。
2)如何将图像的每个像素放大到4乘以图像的每个像素? (不使用插值)

I wrote my code and I have 2 questions1) How can I enlarge 1 pixel into 4 pixels? and also show them.2) How can I enlarge every pixels of image into 4 multiply with every pixels of image? (Not to use interpolation)

编辑

从我的图片我想放大1像素为4像素。

from my image I want to enlarge 1 pixel into 4 pixel.Then all of pixels image must englarged into bigger image.

推荐答案

你需要使用最近邻插值 : cv :: INTER_NEAREST (或 CV_INTER_NN )与:

You need to use nearest-neighbor "interpolation": cv::INTER_NEAREST (or CV_INTER_NN) with cv::resize():

cv::resize(gray, enlarged, cv::Size(gray.rows*2, gray.cols*2), cv::INTER_NEAREST);

最近邻调整大小方案不是真正的插值。它只是选择原始中最接近的像素。当对每个像素放大2倍时,将与您的绘图中重复4次。

The nearest-neighbor resizing scheme is not really interpolation. It just chooses the closest pixel in the original. When enlarging by a factor of 2 to each pixel will be duplicated 4 times as in your drawing.

这篇关于使用opencv放大图片像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:06