android: smooth out edges of random shape bitmap - opencv

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?

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.

Related

Custom GPUImage filter: each pixel is the sum of pixels above it

I'm trying to create a GPUImage filter to determine the bounding box of an image. The process would require the following step: copying the image except for:
pixels on last row is black if at least one of the above pixels is not completely transparent
pixels on last line is black if at least one of the pixels on its left is not completely transparent
pixels on last line is black if it would be according to rule 1. or rule 2.
This would convert image A into image B:
How could I achieve this easily?
GPUImage filters support write shader file for it. You need to write shader that doing provided algorithm. So basically you need to subclass from GPUImageFilter and write shader file. :)

Extraction text line

I need to create iOS app and this app allow user to capture paper and automatically detect text-line and then extract each line as new image.
Example:
Image contains 4 lines of text after process become 4 images and each image contain text line.
Anyone can help me please?
1) First, 3x3 Gaussian blur or some other method to remove noise.
2) Adaptive threshold the image. You have the text as white and rest as black. [You can apply one step of erode after this if you see some small noise elements]
3) Create a kernel to work in x-direction for Dilation. Apply very big dilation like 10 or more. It will dilate you white text in horizontal direction only.
4) Now you have several white rectangles. Extract image from original image where rectangle size and position is taken from above resultant image. You can simply AND both images in case you just want to separate.
Good Luck and happy coding.

How to detect large galaxies using thresholding?

I'm required to create a map of galaxies based on the following image,
http://www.nasa.gov/images/content/690958main_p1237a1.jpg
Basically I need to smooth the image first using a mean filter then apply thresholding to the image.
However, I'm also asked to detect only large galaxies in the image. So what should I adjust the smoothing mask or thresholding in order to achieve that goal?
Both: by smoothing the picture first, the pixels around smaller galaxies will "blend" with the black space and, thus, shift to a lower intensity value. This lower intensity can then be thresholded, leaving only the white centres of bigger galaxies.

rotated crop in opencv

I am trying to crop a picture on right on along the contour. The object is detected using surf features and than i want to crop the image of extactly as detected.
When using crop some outside boundaries of other object is includes. I want to crop along the green line below. OpenCV has RotatedRect but i am unsure if its good for cropping.
Is there way to perfectly crop along the green line
I assume you get you get your example from http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html, so what you can do is to find the minimum axis aligned bounding box around the green bounding box, crop it from the image, use the inverted homography (H.inv()) matrix to transform that sub image into a new image (call cv::warpPerspective), and then crop your green bounding box (it should be axis aligned in your new image).
You can get the equations of the lines from the end points for each. Use these equations to check whether any given pixel lies within the green box or not i.e. does it lie between the left and right lines and between the top and bottom lines. Run this over the entire image and reset anything that doesn't lie within the box to black.
Not sure about in-built functionality to do this, but this simple methodology is guaranteed to work. For higher accuracy, you may want to consider sub-pixel checks.

Segmenting circle-like shapes out of Binary Image

I have several binary images and my task is to segment circle-like shape. The circles are not perfect rounded circle, but all of them will look like circle. Here are some example images and what I need:
As you can see from above, the left images are original images, and the right images are what I need to do. The circles intersect with other shapes, but I only want the circle, as indicated in red. The imaginary lines to close the circle will be required. What can I do in this case in Image Processing?
EDIT: in case, the image above is broken, here: http://imageshack.us/photo/my-images/835/circleonly.jpg/
Do you know the radii of the disks you are looking for?
If yes, morphological openings (erosion then dilation) would be straightforward, and very fast. The result using Mathematica:
Opening[img, DiskMatrix[15]]
If not, as other proposed, computing the contour image and then using the Hough transform would be a method worth pursuing. The image just above shows the contour image.
You can use hough transform, first you need is the edge image then you use a hough transform like you can see in this papers
http://www.cis.rit.edu/class/simg782/lectures/lecture_10/lec782_05_10.pdf
http://www.sci.utah.edu/~gerig/CS6640-F2010/FINALPROJECT/Ballard-GHT-1981.pdf
http://www.sciencedirect.com/science/article/pii/003132039290064P
http://www.markschulze.net/java/hough/

Resources