问题
I have an random shape bitmap cut out by user. I want to fade out its borders i.e. contours, so as to make it appear smooth. What should I do? To get the borders and color of every pixel in bitmap, I am traversing it pixel by pixel. It takes long time, still I am ok with it. Is openCV my only option? If yes, can anybody point me towards any tutorial or suggestion for logical approach?
回答1:
You can just run a smoothing filter on your shape.
In opencv you can use the blur fnnction or gaussainBlur. Look at http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html.
You don't have to use opencv but i think it would be easier and faster.
If you still don't want can use any other code that implement smoothing an image.
In case you just want to effect the border pixels do the following:
- Make a copy of the original image
- Filter the entire image.
- Extract the border pixel using opencv findContours.
- Copy from the blurred image only the pixels in the border and in there neighborhood and copy them to the copy you did in step 1.
来源:https://stackoverflow.com/questions/39163814/android-smooth-out-edges-of-random-shape-bitmap