Ask Your Question

OmerAslam's profile - activity

2019-11-21 22:04:08 -0500 received badge  Popular Question (source)
2016-12-08 02:29:55 -0500 commented question Smoothing edges change black color

plz tell me how to solve this issue

2016-12-07 12:44:39 -0500 asked a question Smoothing edges change black color

I am getting foreground image from grabCut algorithm and then i apply below algorithm to smooth its edges. It is working fine and smoothing edges but it is also changing black color in the image.

You can see for this image it is working fine for this image image description but for this image it is changing black color image description
please tell me how to fix this.

This is my code for edge smoothing and i got it from Image edge smoothing with opencv

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char **argv)

Mat originalImage = imread("../data/original_image_1.jpg");
Mat grabCutImage = imread("../data/grab_cut_image_1.png"); // got from grabcut algorithm

originalImage.convertTo(originalImage, CV_32FC3, 1.0 / 255.0);
resize(originalImage, originalImage, grabCutImage.size());
grabCutImage.convertTo(grabCutImage, CV_32FC3, 1.0 / 255.0);

Mat bg = Mat(grabCutImage.size(), CV_32FC3);
bg = Scalar(1.0, 1.0, 1.0);

Mat mask;
Mat img_gray;
cvtColor(grabCutImage, img_gray, COLOR_BGR2GRAY);
img_gray.convertTo(mask, CV_32FC1);
threshold(1.0 - mask, mask, 0.9, 1.0, THRESH_BINARY_INV);

GaussianBlur(mask, mask, Size(21, 21), 11.0);

Mat smooth;

vector<Mat> ch_img(3);
vector<Mat> ch_bg(3);
split(originalImage, ch_img);
split(bg, ch_bg);
ch_img[0] = ch_img[0].mul(mask) + ch_bg[0].mul(1.0 - mask);
ch_img[1] = ch_img[1].mul(mask) + ch_bg[1].mul(1.0 - mask);
ch_img[2] = ch_img[2].mul(mask) + ch_bg[2].mul(1.0 - mask);
merge(ch_img, smooth);
merge(ch_bg, bg);

imshow("originalImage", originalImage);
imshow("grabCutImage", grabCutImage);
imshow("smoothImage", smooth);

here are images i am using

image description image description image description image description

2016-12-01 03:36:05 -0500 commented answer Smooth or blur image edges using opencv

LBerger can u give me some code

2016-12-01 02:06:50 -0500 asked a question Smooth or blur image edges using opencv

I want to feathere smooth or blur image edges using opencv.

This is what i tried

int lowThreshold = 100;
int ratio = 3;
int kernelSize = 3;

Mat srcGray, cannyEdges, blurred;
cvtColor(input, srcGray, CV_BGR2GRAY);
blur(srcGray, cannyEdges, Size(3, 3));
Canny(cannyEdges, cannyEdges, lowThreshold, lowThreshold * ratio, kernelSize);

int dilation_size = 5;
Mat element = getStructuringElement(MORPH_CROSS,
                                Size(2 * dilation_size + 1, 2 * dilation_size + 1),
                                Point(dilation_size, dilation_size));

dilate(cannyEdges, cannyEdges, element);
blur(blurred, blurred, Size(3, 3));
blurred.copyTo(output, cannyEdges);

This is the image of my input, my output and desired result image description

i am using this image as input image description