How does one blur a circular portion of an image in the python bindings of Open CV. Can one apply blurring on images without making new images?
It doesn't look like the OpenCV's blurring and filtering functions allow masking the input. I suggest applying the filter on a Rect around the circular portion, then assign the elements of the blurred sub matrix to the original image while masking the elements that do not correspond to the circle.
Related
initial mask
I have the above mask which is roughly the shape of a trapezium and want to convert it to this. This would mean the sides were straightened - especially the front side of the mask. I want to alter this mask to straighten the edges and not just create a mask with a trapezium shape of the same size as I want to repeat this process on other masks without the trapezium shape and vary for other masks with different shapes, most not regular.
Is this possible?
Tried dilating and eroding without desired effects, although realised this would likely have little affect after.
For this task, I guess method cv2.findContours() will be helpful.
After you get the contours of your mask, you can play around with cv2.approxPolyDP() function to approximate your figure into some polygon. If you want your polygon to be convex, try cv2.convexHull(), also try cv2.boundingRect() or cv2.MinAreaRect(), though they will produce a right rectangle and rotated rectangle respectively.
Either way, try reading this article for more details on how to work with your mask. Though, there might be much more suitable functions in opencv for your current task.
I am programmatically processing satellite images and using Rasterio to clip my Area of Interests. All my rasterio masks are currently in the 1:1 aspect ratio (square). I have a specific case where in the clipping mask boundaries fall outside the image bounds. I would like to fill the empty areas with dummy pixels of a specific color, instead of the program clipping my image lazily.
The image above shows my current and expected scenario. Basically I would like to preserve my target aspect ratio (1:1) regardless of whether the clipping area is inside or outside of my main image. Is there a function in Rasterio that I can make use of?
I also have an idea in mind using cv2 where I can compare the pixels in and out and colour them conditionally but quite unsure where to start.
For an assignment, The image corrupted by atmospheric turbulence. I want to deblur an image using inverse image filtering. I have done some research and it seems I need the original image for this procedure but I only have the blurred image. How can I construct the degrading function that was used to blur this image? I am not allowed to use the original image. Thank you in advance.
This is the image:
I have an image which has roots like this:
I want to crop each root individually out.
I initially thought of heavy dilation followed by erosion and contour detection of the blob, but since the roots are thin, it does not work well.
I also directly applied canny edge and contour detection like this image below. It has around 62000 contours, but I cannot use it to get the outline of each root.
I also thresholded the image using HSV followed by some median blurring. But it did not reduce much noise. Further blurring only leads to losing the root features.
Can anyone suggest me a better approach to tackle this problem? Will any Machine Learning based approach work better? Thanks
Use Cv2.BoundingRect(), it gets the rectangle area of your contour. Also you can use MedianFilter to get rid of "salt and pepper" noise in your picture.
First step detect big root, by user select or big erosion.
Second step base on previous big area center coordinate, make a fill algorithm (like Paint Bucket Tool in Paint) on this original threshold image
I am using OpenCV's Optical Flow module. I understand the examples in the documentation but those take the entire image and then get the optical flow over the image.
I only want to pass it over some parts of an image. Is it possible to do that? If yes, how do I go about it?
Thanks!
Yes, it's possible. cv2.calcOpticalFlowPyrLK() will be the optical flow function you need. Before you make that function call, you will have to create an image mask. I did a similar project, but in C++, though I can outline the steps for you:
Create an empty matrix with same width and height of your images
Using the points from your ROI, create a shape out of it (I did mine using cv2.fillPoly()) and fill the inside of the shape with white (Your image mask should only be comprised of black and white color)
If you are planning on using corners as features, then call cv2.goodFeaturesToTrack() and pass in the mask you've made as one of its arguments.
If you're using the Feature2D module to detect features, you can use the same mask to only extract the features in that masked area.
By this step, you should now have a collection of features/points that are only within the bounds of the shape! Call the optical flow function and then process the results.
I hope that helps.