Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

My propose is: 1. Color--->Gray the you threshold, and thresvalue:240~255 2. use Morphy methold to remove the blob cross the left side. and you can get you want.

My propose is: 1. is:

  1. Color--->Gray the you threshold, and thresvalue:240~255 2. thresvalue:240~255

  2. use Morphy methold to remove the blob region cross the left side. and you can get you want.

My propose is:

  1. Color--->Gray the you Color to Gray, then use threshold, and thresvalue:240~255

  2. use Morphy methold to remove the region cross the left side. and you can get you want.

My propose is:

  1. Color to Gray, then use threshold, and thresvalue:240~255

  2. use Morphy methold to remove the region cross the left side. and you can get you want.

    void CV_EXPORTS MorpRemoveBoderObj(InputArray _src, OutputArray _dst,InputArray se) { Mat src=_src.getMat(); _dst.create(src.size(),CV_8UC1); Mat dst=_dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); cv::Mat temp; temp.create(src.size(),CV_8UC1); temp.setTo(0); cv::rectangle(temp, cv::Point(3,3), cv::Point(temp.cols-3, temp.rows-3), CV_RGB(255,255,255), -1);// --->here you must reserve only left side, not a rectangle cv::subtract(255,temp,temp); MorpRDilate(temp, src, dst,sem,-1); cv::subtract(src, dst, dst); }

void CV_EXPORTS MorpRDilate(InputArray _src, InputArray _mask, OutputArray _dst, InputArray se ,int iterations) { Mat src=_src.getMat(); _dst.create(src.size(), src.type()); Mat dst = _dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); Mat mask=_mask.getMat(); //imshow("src",src); //imshow("mask",mask); CV_Assert(src.cols==mask.cols && src.rows == mask.rows); assert(src.cols == mask.cols && src.rows == mask.rows ); if(iterations < 0) { cv::min(src, mask, dst); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); Mat temp1,temp2; temp1.create(src.size(),CV_8UC1); temp2.create(src.size(),CV_8UC1); do { temp1=dst.clone(); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); cv::compare(temp1, dst, temp2, CV_CMP_NE ); /imshow("temp1",temp1); imshow("dst",dst); imshow("temp2",temp2);/ } while(cv::sum(temp2).val[0] != 0);

    //return;
}
else if (iterations == 0)
{
    dst=src.clone();
    //cvCopy(src, dst);
}
else
{
    cv::min(src,mask,dst);
    cv::dilate(dst,dst,sem);
    cv::min(dst,mask,dst);
    for(int i=1; i<iterations; i++)
    {
        cv::dilate(dst, dst, sem);
        cv::min(dst, mask, dst);
    }
}

}

My propose is:

  1. Color to Gray, then use threshold, and thresvalue:240~255

  2. use Morphy methold to remove the region cross the left side. and you can get you want.

    void CV_EXPORTS MorpRemoveBoderObj(InputArray _src, OutputArray _dst,InputArray se) { Mat src=_src.getMat(); _dst.create(src.size(),CV_8UC1); Mat dst=_dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); cv::Mat temp; temp.create(src.size(),CV_8UC1); temp.setTo(0); cv::rectangle(temp, cv::Point(3,3), cv::Point(temp.cols-3, temp.rows-3), CV_RGB(255,255,255), -1);// --->here you must reserve only left side, not a rectangle cv::subtract(255,temp,temp); MorpRDilate(temp, src, dst,sem,-1); cv::subtract(src, dst, dst); }

void CV_EXPORTS MorpRDilate(InputArray _src, InputArray _mask, OutputArray _dst, InputArray se ,int iterations) { Mat src=_src.getMat(); _dst.create(src.size(), src.type()); Mat dst = _dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); Mat mask=_mask.getMat(); //imshow("src",src); //imshow("mask",mask); CV_Assert(src.cols==mask.cols && src.rows == mask.rows); assert(src.cols == mask.cols && src.rows == mask.rows ); if(iterations < 0) { cv::min(src, mask, dst); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); Mat temp1,temp2; temp1.create(src.size(),CV_8UC1); temp2.create(src.size(),CV_8UC1); do { temp1=dst.clone(); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); cv::compare(temp1, dst, temp2, CV_CMP_NE ); /imshow("temp1",temp1); imshow("dst",dst); imshow("temp2",temp2);/ } while(cv::sum(temp2).val[0] != 0);

0);
        //return;
 }
 else if (iterations == 0)
 {
     dst=src.clone();
     //cvCopy(src, dst);
 }
 else
 {
     cv::min(src,mask,dst);
     cv::dilate(dst,dst,sem);
     cv::min(dst,mask,dst);
     for(int i=1; i<iterations; i++)
    {
        cv::dilate(dst, dst, sem);
        cv::min(dst, mask, dst);
    }
}

}i++)="" {="" cv::dilate(dst,="" dst,="" sem);="" cv::min(dst,="" mask,="" dst);="" }="" }="" }<="" p="">

My propose is:

  1. Color to Gray, then use threshold, and thresvalue:240~255

  2. use Morphy methold to remove the region cross the left side. and you can get you want.

    void CV_EXPORTS MorpRemoveBoderObj(InputArray _src, OutputArray _dst,InputArray se) { Mat src=_src.getMat(); _dst.create(src.size(),CV_8UC1); Mat dst=_dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); cv::Mat temp; temp.create(src.size(),CV_8UC1); temp.setTo(0); cv::rectangle(temp, cv::Point(3,3), cv::Point(temp.cols-3, temp.rows-3), CV_RGB(255,255,255), -1);// -1); // --->here you must reserve only left side, not a rectangle cv::subtract(255,temp,temp); MorpRDilate(temp, src, dst,sem,-1); cv::subtract(src, dst, dst); }

    void CV_EXPORTS MorpRDilate(InputArray _src, InputArray _mask, OutputArray _dst, InputArray se ,int iterations) { Mat src=_src.getMat(); _dst.create(src.size(), src.type()); Mat dst = _dst.getMat(); Mat sem=se.getMat(); if(sem.empty()) sem= cv::getStructuringElement(MORPH_CROSS,cv::Size(3, 3),cvPoint(-1,-1)); Mat mask=_mask.getMat(); //imshow("src",src); //imshow("mask",mask); CV_Assert(src.cols==mask.cols && src.rows == mask.rows); assert(src.cols == mask.cols && src.rows == mask.rows ); if(iterations < 0) { cv::min(src, mask, dst); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); Mat temp1,temp2; temp1.create(src.size(),CV_8UC1); temp2.create(src.size(),CV_8UC1); do { temp1=dst.clone(); cv::dilate(dst, dst, sem); cv::min(dst, mask, dst); cv::compare(temp1, dst, temp2, CV_CMP_NE ); /imshow("temp1",temp1); imshow("dst",dst); imshow("temp2",temp2);/ } while(cv::sum(temp2).val[0] != 0); //return; } else if (iterations == 0) { dst=src.clone(); //cvCopy(src, dst); } else { cv::min(src,mask,dst); cv::dilate(dst,dst,sem); cv::min(dst,mask,dst); for(int i=1; i<iterations; i++)="" {="" cv::dilate(dst,="" dst,="" sem);="" cv::min(dst,="" mask,="" dst);="" }="" }="" }<="" p="">