Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...