Ask Your Question

gdarmon's profile - activity

2016-03-12 15:00:25 -0600 answered a question Median filter greater than 5.

I haven;t tried it, but have a look here, it is the same algorithm as openCV's however it is extended to 16 bits per pixel,

2016-03-12 11:50:16 -0600 asked a question Median filter support for large kernel

in the documentation medianBlur(InputArray src, OutputArray dst, int ksize)

src – input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.

Large aperture size are not supported for more than 8 bit. Can someone please explain why? I'm trying to convert matlab code which uses medfilt2 function with a 7x7 kernel, however my image is 16 bits per pixel.

I know that openCV integrated this algorithm into median filter

Is there a plan to add 16 bit support for large kernels? I would like to try to use Intel Cilk plus to optimize the code for larger bits and larger kernels. has anyone come across this issue before? optimizing for 7x7 kernel for 16 bit depth images?

2015-09-07 02:55:33 -0600 received badge  Supporter (source)
2015-09-06 08:42:51 -0600 commented question FindContours hirerarcy issue

@LBerger I added the original image, I don't know what you mean by parity test.. Can you explain please?

2015-09-06 08:24:18 -0600 received badge  Editor (source)
2015-09-06 07:56:27 -0600 asked a question FindContours hirerarcy issue

I'm trying to convert the following Matlab code into openCV. My code works really great for most of the examples I have(~700), except this one.

Original Image
image description

Here is the matlab output:

image description

Here is the openCV output: image description

Here is what happens when I remove CV_Fill: image description

% Convert to BW image
 bwImg = im2bw(imageData, grayThresh);

% If we end up with totally black or white image return false status.
if all(bwImg(:)) || all(~bwImg(:))
    status = false;
    cornerXY = [];
    centroidXY = [];
    centroidMedianDistance = [];

  % Calculate each separated object area
cDist=regionprops(bwImg, 'Area');

% Label each object
[bwImgLabeled, ~]=bwlabel(bwImg);

% Calculate min and max object size based on assumptions on the color
% checker size
maxLabelSize = prod(size(imageData)./[4 6]);
minLabelSize = prod(size(imageData)./[4 6]./10);

% Find label indices for objects that are too large or too small
remInd = find(cDist > maxLabelSize);
remInd = [remInd find(cDist < minLabelSize)];

% Remove over/undersized objects
for n=1:length(remInd)
    ri = bwImgLabeled == remInd(n);
    bwImgLabeled(ri) = 0;

% Fill any holes in the objects
bwImgLabeled = imfill(bwImgLabeled,'holes');

% Re-label the result image objects
bwImgLabeled(bwImgLabeled>0) = 1;
[bwImgLabeled, nObjs] = bwlabel(bwImgLabeled);

Here is my C++/OpenCV code

cv::Mat bwImg = Utilities::im2bw(imageData, grayThresh);    

double sum = cv::sum(bwImg)[0];
if(sum == bwImg.rows * bwImg.cols||sum == 0 )
    return AutomaticMacbethDetectionResults(false);

cv::vector<cv::vector<cv::Point> > contours_1;
cv::vector<cv::Vec4i> hierarchy_1;
cv::findContours(bwImg,contours_1,hierarchy_1,CV_RETR_TREE,   CV_CHAIN_APPROX_SIMPLE,cv::Point(0,0));*/

cv::vector<cv::vector<cv::Point> > contours_1;
cv::vector<cv::Vec4i> hierarchy;

double maxLabelSize = (bwImg.rows/4.0) * (bwImg.cols/6.0);
double minLabelSize = ((bwImg.rows/40.0) * (bwImg.cols/60.0));

//OPENCV hierarchy *[Next, Previous, First_Child, Parent]**

cv::vector<cv::vector<cv::Point> > goodContours;
    for (int i = 0; i < contours_1.size(); i++)
    double size = cv::contourArea(contours_1[i]);
    if (size < maxLabelSize && size > minLabelSize) //I added my check for hierarachy[i][2] ==-1 here! 

cv::Mat filterContours = cv::Mat::zeros(bwImg.size(),CV_8UC3);  
for (int i = 0; i < goodContours.size(); i++)
    cv::RNG rng(12345);
    cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );

imageData = filterContours;
/*% Re-label the result image objects
bwImgLabeled(bwImgLabeled > 0) = 1;*/
cv::threshold(imageData, imageData, 0 ,254,CV_THRESH_BINARY);

so as far as I understand I can use the Hierarchy feature in order to understand if there is a contour which holds other contours. Hierarchy

and I added a switch to check for hierarchy[i][2] == -1 (meaning it has no children)

however this ruins my results for other images. Can you please explain the difference between regionprops and findcontours? and maybe suggests a way to solve my issue?