1

So, I have an image cv::Mat created as an indexed 2D matrix with colors 1,2,3,... up to 255. I want to resize my image all at once but do it like I currently do - individually for each index, so as not to get mixed colors:

//...
std::map<unsigned char , cv::Mat* > clusters;
for(int i = 0; i < sy; ++i)
{
    for(int j = 0; j < sx; ++j)
    {
        unsigned char current_k = image[i][j];
        if (clusters[current_k] == NULL) {
            clusters[current_k] = new cv::Mat();
            (*clusters[current_k]) = cv::Mat::zeros(cv::Size(sx, sy), CV_8UC1);
        }
        (*clusters[current_k]).row(i).col(j) = 255;
    }
}

std::vector<cv::Mat> result;
for( std::map<unsigned char, cv::Mat*>::iterator it = clusters.begin(); it != clusters.end(); ++it )
{
    cv::Mat filled(cv::Size(w, h), (*it->second).type());
    cv::resize((*it->second), filled, filled.size(), 0,0, CV_INTER_CUBIC);

    cv::threshold( filled, filled, 1, 255, CV_THRESH_BINARY);
    result.push_back(filled);
}

So, can OpenCV help me with the automation of my indexed image (so that I could not create cv::Mat per each cluster for a correct resize)?

mevatron
  • 13,911
  • 4
  • 55
  • 72
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
  • It would help if you a comparison posted results of your resize method vs the results of using OpenCV image resizing functions. In particular, I'd be interested in seeing how your method compares to nearest-neighbor resizing. – mpenkov Nov 25 '11 at 07:05

1 Answers1

1

you can use the Remap function with your own mash to interpolate the values as you'de like

take a look at this tutorial (Link)

Boaz
  • 4,549
  • 2
  • 27
  • 40