Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

c++ - Enlarge image pixels with 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);

I wrote my code and I have 2 questions 1) 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)

Edit

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...