Ask Your Question
2

How to remove the fine hair on the hand back image

asked 2017-12-27 02:45:36 -0600

sushiqian gravatar image

updated 2020-10-25 13:27:39 -0600

I want to enhance the hand back imge, see the below image: image description

After enhance it, I got the below image, image description

My question is how to remove the fine hair on the hand back image? see the below image, I want to remove the fine hair(such as, the line enclosed in the red line), but, need to keep the vein(such as, the line enclosed in the green line)

image description

edit retag flag offensive close merge delete

Comments

Easier way to do this is grabcut. Can be found in OpenCV' s folder.

supra56 gravatar imagesupra56 ( 2017-12-27 03:57:16 -0600 )edit

3 answers

Sort by » oldest newest most voted
1

answered 2017-12-31 16:14:39 -0600

edit flag offensive delete link more

Comments

Hands down best solution!

sjhalayka gravatar imagesjhalayka ( 2017-12-31 18:11:04 -0600 )edit

This is some simpler C++ code that I used to replicate sturkmen's algorithm:

Mat frame = imread("hand.png");

if (frame.empty())
{
    cout << "File read error" << endl;
    return 0;
}

int dilation_size = 2;
Mat dilation_element = getStructuringElement(
    MORPH_RECT,
    Size(2 * dilation_size + 1, 2 * dilation_size + 1),
    Point(dilation_size, dilation_size));

dilate(frame, frame, dilation_element);

imshow("frame", frame);
waitKey();

I'm deleting my own answer.

sjhalayka gravatar imagesjhalayka ( 2017-12-31 18:29:07 -0600 )edit

@sjhalayka. That's not solution. He merely wanted removing part of red lines only. Not all of them.

supra56 gravatar imagesupra56 ( 2017-12-31 20:38:14 -0600 )edit

Are you francophone?

sjhalayka gravatar imagesjhalayka ( 2017-12-31 21:59:04 -0600 )edit

Click my name.

Edit: Btw, Happy New Years!

supra56 gravatar imagesupra56 ( 2017-12-31 22:39:47 -0600 )edit

A half hour to go here in Saskatchewan. :) Happy New Year!

sjhalayka gravatar imagesjhalayka ( 2017-12-31 23:34:29 -0600 )edit

@sjhalayka BBBRRRrrrrrrr in your area. I was thinking about your code that you posted as above. Draw a rectangle to selected unwanting hair by using mouseevent method then apply your code. Then save image.

supra56 gravatar imagesupra56 ( 2018-01-01 07:39:53 -0600 )edit

Yeah it was -38C the other day, plus wind. Not fun. :) I just read about La Grande Rivière, Que., which reached -48C. That would just suck.

sjhalayka gravatar imagesjhalayka ( 2018-01-01 10:34:02 -0600 )edit
0

answered 2017-12-31 15:36:05 -0600

I tried to solve your problem with the idea that you need a method applicable to similar images. So, I wrote a small algorithm that read the pixels of the image and detect when there's a sudden change in intensity(0-255) and blur the subregion. Particularly, I create an imaginary rectangle(1x9 pixel) which I iterate through the image. For each movement of the rectangle I iterate IN it vertically(that is, read 9 vertical pixels) and check for sudden delta in intensity(in this case 30) and blur that area with a normal blur. But before doing all this, I apply a threshold to highlight the hair. The result is not exactly what you asked but hey, I enjoyed myself :-). Here's the code:

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main()
{
    Mat image;
    image = imread("hand.jpg", IMREAD_GRAYSCALE);
    if (image.data==NULL)
        cout << "Img not found" << endl;
    namedWindow("hand", WINDOW_AUTOSIZE);
    Mat orig = image.clone();
    threshold(image, image, 180, 255, THRESH_BINARY);

    int height = 8;
    for(int x=0;x<image.cols;x++)
        for (int y = height / 2; y < image.rows - height / 2; y++)
        {
            int whiteToBlack = 0, blackToWhite = 0;
            for (int rectY = y - height / 2; rectY < y + height / 2 - 1; rectY++)
                if (image.at<uchar>(rectY, x) > image.at<uchar>(rectY + 1, x) && image.at<uchar>(rectY, x) - image.at<uchar>(rectY + 1, x) > 30)
                    whiteToBlack++;
                else if (image.at<uchar>(rectY, x) < image.at<uchar>(rectY + 1, x) && image.at<uchar>(rectY + 1, x) - image.at<uchar>(rectY, x) > 30)
                    blackToWhite++;
            if (whiteToBlack > 0 && blackToWhite > 0)
                for (int rectY = y - height / 4; rectY < y + height / 4 - 1; rectY++)
            blur(orig(Rect(x, y - height / 2, 4, height + 1)), orig(Rect(x, y - height / 2, 4, height + 1)),Size(3,3));
        }

    imshow("hand", orig);
    waitKey(0);
}

The result: image description

edit flag offensive delete link more
0

answered 2017-12-28 10:39:24 -0600

supra56 gravatar image

The inpaint can be found on Opencv's folder either cpp or python2 C:\fakepath\Unwanted hair removed.jpg

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-12-27 02:45:36 -0600

Seen: 1,660 times

Last updated: Dec 31 '17