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.
Related
Newbie in image processing. I'm confused with these methods when merging two images with Pillow:
PIL.Image.Image
.paste()
.composite()
.alpha_composite()
.blend()
Could anyone provide a quick explanation? Or where could I grab the related background knowledge?
I see it like this:
blend is the simplest. It takes a fixed and constant proportion of each image at each pixel location, e.g. 30% of image A and 70% of image B at each location all over the image. The ratio is a single number. This operation is not really interested in transparency, it is more of a weighted average where a part of both input images will be visible at every pixel location in the output image
paste and composite are synonyms. They use a mask, with the same size as the images, and take a proportion of image A and image B according to the value of the mask which may be different at each location. So you might have a 0-100 proportion of image A and image B at the top and 100-0 proportion at the bottom, and this would look like a smoothly blended transition from one image at the top to the other image at the bottom. Or, it may be like a largely opaque foreground where you only see one input image, but a transparent window through which you see the other input image. The mask, of the same size as the two input images, is key here and it can assume different values at different locations.
alpha compositing is the most complicated and is best described by Wikipedia
——-
Put another way, blend is no alpha/transparency channel and a fixed proportion of each input image present throughout the output image.
paste is a single alpha channel that can vary across the image.
alpha_composite is two alpha channels that can both vary across the image.
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.
Actually, I want five external bounding boxes for the "white" pixels on the following binary image. Desired zones are highlighted with red color.
To get 5th bounding box I'd dilate or blur it. However, dilation will merge zone 3 with zones 1 and 2, so I'll get a bounding box which covers almost entire image. (If I don't dilate or blur it, then cv::findContours + cv::boundingRect will produce a big number of small rectangles.)
In other words, I want only "big enough" bounding boxes.
It's just a sample pattern. Positions of the zones may vary. Is there a way to solve the problem in a general way?
Dilation is done at a per-pixel basis, without regard for the size of the component to which the pixel belongs.
If you want to apply dilation only to small blobs, then you need to remove big blobs before applying the dilation.
So, extract all contours with findContours, then store all contours that are 'big enough' in a list, and paint them black in your source image. Then dilate the modified source and extract the remaining contours.
Note that to get the correct size of the boundingBox, what you probably want is morphological closing (dilation followed by the same amount of erosion), instead of dilation only.
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.
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.