android: smooth out edges of random shape bitmap

大兔子大兔子 提交于 2020-05-28 09:25:40

问题


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:

  1. Make a copy of the original image
  2. Filter the entire image.
  3. Extract the border pixel using opencv findContours.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!