Ask Your Question
0

Output image which combine pixels from different smoothing filter mask

asked 2013-05-26 09:47:19 -0500

william gravatar image

updated 2013-05-30 10:18:18 -0500

Hi, please help.

How do I write code using OpenCV for the problem below:

Given an input image f(x), I want to produce an output image g(x) with: 1) first pixel using the original pixel value 2) second pixel with 3x3 smoothing filter mask value and 3) third pixel with 5x5 smoothing filter mask value

The remaining pixels will repeat the above 3 steps until the last pixels.

Currently I am able to produce the smooth image of 3x3 and 5x5 mask filter. However i cant figure out how to combine this smooth pixels into one output image g(x) like the condition given above.

Please help and advise.

Thank you very much.


Below is my code for the above question. The compilation error is: (error C2106: '=' : left operand must be l-value). This error flag when assigning pixel for the output image with first pixel using original image pixel, second pixel using 3x3 filter mask pixel value, third pixel using 5x5 filter mask pixel value.

include <iostream>

include <fstream>

include <math.h>

include "cv.h"

include "highgui.h"

include <create _own="" histogram.h="">

int image_height; int image_width; cv::Mat image; Histogram1D h; using namespace std;

int main() {

// Read input image
image= cv::imread("fl.pgm",0);
std::cout << "size: " << image.size().height << " , " << image.size().width << std::endl;
if(!image.data)
return 0;
cv::Mat imageClone3= image.clone();
cv::Mat imageClone5= image.clone();
cv::Mat result_3(image_height, image_width, CV_8U,cv::Scalar(255));
cv::Mat result_5(image_height, image_width, CV_8U,cv::Scalar(255));
cv::Mat OutputImage(image_height, image_width, CV_8U,cv::Scalar(255));

image_height = image.rows;
image_width = image.cols;

    //Display the image
cv::namedWindow("Image");
//cv::namedWindow("result_3");
cv::imshow("Image",image);

cv::Mat image3, image5; cv::GaussianBlur(imageClone3,result_3,cv::Size(3,3),0,0); //3x3 filter mask cv::GaussianBlur(imageClone5,result_5,cv::Size(5,5),0,0); //5x5 filter mask

cv::namedWindow("Image Result_3"); cv::imshow("Image Result_3",result_3); cv::imwrite("3x3.bmp",result_3);

cv::namedWindow("Image Result_5"); cv::imshow("Image Result_5",result_5); cv::imwrite("5x5.bmp",result_5);

for (int i=0; i<image_height; i++)="" for="" (int="" j="0;" j<image_width;="" j++)="" {="" if(j%3="=0)" int(outputimage.at<uchar="">(i,j)) = int(image.at<uchar>(i,j)); //first pixel of output image using the original input pixel value

            else if(j%3==1)
    int(OutputImage.at<uchar>(i,j)) = int(result_3.at<uchar>(i,j)); // second pixel of output image using 3x3 filter mask 

    else if(j%3==2)
    int(OutputImage.at<uchar>(i,j)) = int(result_5.at<uchar>(i,j)); // third pixel of output image using 5x5 filter mask 

            }
  cv::namedWindow("Out");
  cv::imshow("Out",OutputImage);

cv::waitKey();
return 0;

}

Please help me to solve the above problem. Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-05-26 13:55:49 -0500

Notas gravatar image

Simply iterate over each pixel in your image and just use a variable that you increase after each operation to indicate which operation to apply on the current pixel (value stays, use pixel from 3x3 image, use pixel from 5x5 image).

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-26 09:47:19 -0500

Seen: 755 times

Last updated: May 30 '13