Ask Your Question
0

make edges clearer in image

asked 2019-02-21 06:07:59 -0500

I'm currently preprocessing a few images before I can use them for edge detection and I need to make the edges more clear so that the edge algorithm (Canny and Hough) can find them more easily without the need to reconfigure the thresholds. The only important part of the photo that I need are the edges from the items on the pile, the rest is irrelevant.

I have the following images: image description image description

How would you make the edges between the items on the pile stand out?

edit retag flag offensive close merge delete

Comments

show, what you have, so far, and the code for it ?

berak gravatar imageberak ( 2019-02-21 06:22:53 -0500 )edit

I've currently tried the following:

# Remove some noise by closing (erode and dilate)
kernel = np.ones((5, 5), np.uint8)
image_to_process = cv.morphologyEx(image_to_process, cv.MORPH_OPEN, kernel)
process_image_hsv = cv.cvtColor(image_to_process, cv.COLOR_BGR2HSV)

# Mask the image
lower_bound = np.array([13, 34, 0], np.uint8)
upper_bound = np.array([69, 255, 57], np.uint8)

mask1 = cv.inRange(process_image_hsv, lower_bound, upper_bound)
mask1 = cv.bitwise_not(mask1)

lower_bound = np.array([5, 84, 9], np.uint8)
upper_bound = np.array([20, 255, 157], np.uint8)

mask2 = cv.inRange(process_image_hsv, lower_bound, upper_bound)
mask2 = cv.bitwise_not(mask2)

mask = cv.addWeighted(mask1, 0.5, mask2, 0.5, 1 )
Tom_ColdenhoffVMT gravatar imageTom_ColdenhoffVMT ( 2019-02-21 06:31:32 -0500 )edit

with the following results: image descriptionimage description

EDIT: images don't seem to load. Here are the URL's https://imgur.com/a/LDxzY6Mhttps://imgur.com/a/OxdRbEs

Tom_ColdenhoffVMT gravatar imageTom_ColdenhoffVMT ( 2019-02-21 06:34:04 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-02-22 11:00:17 -0500

For many machine vision problems, lighting can be very important. I recommend playing around with the lighting to make it more consistent in the image and try dark-field illumination.

image description

I was able to find many of the edges your looking for with the code below.

image description

    Mat img, gaussImg, laplaceImg, thresholdImg, lineImg, markupImg;

img = imread("Clipboard01.png");
cvtColor(img, gaussImg, COLOR_BGR2GRAY);
for (int i = 0; i < 8; i++) {
    GaussianBlur(
        gaussImg,
        gaussImg,
        Size(3, 3),
        0.5, 0.5, 4);
}

Laplacian(gaussImg, laplaceImg, CV_8UC1, 5);

threshold(laplaceImg, thresholdImg, 125, 255, THRESH_BINARY);
vector <Vec4i> lineList;
HoughLinesP(thresholdImg, lineList, 1.0, 1.0 * CV_PI / 180.0, 100, 100, 4);

cvtColor(thresholdImg, markupImg, COLOR_GRAY2BGR);

for (auto& ptList : lineList) {
    line(markupImg, Point(ptList(0), ptList(1)), Point(ptList(2), ptList(3)), Scalar(200, 0, 200));
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-02-21 06:07:59 -0500

Seen: 175 times

Last updated: Feb 22