I have an RGB image and a binary mask of same dimensions. I want to blur only those portions of the RGB image where the value of mask is 255 (white). How to do this in OpenCV Python?
I tried implementing the method given in the answer of morotspaj in Smoothing Mat of float with mask but didn't quite get the result I was expecting. Can someone explain it?
Related
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 a grey scale image, and I want to convert the image to represent the red channel of an RGB image. How would I do this in Open CV?
You're looking for cv2.merge(). Use the grayscale image as the b channel and use similar sized empty matrices for g and r.
You'll find some help here on how to go about it.
I have obtained boolean matrix from sauvola thresholding using scikit image library now I want to do further processing like blob detection on image. How to convert map boolean matrix to grayscale binary image in python.
Followed this link https://stackoverflow.com/a/47667753/9155046
but the output image need to be mapped to grayscale.
I want to convert the picture into black and white image accurately where the seeds will be represented by white color and the background as black color. I would like to have it in python opencv code. Please help me out
I got good result for the above picture using the given code below. Now I have another picture for which thresholding doesn't seem to work. How can I tackle this problem. The output i got is in the following picture
also, there are some dents in the seeds, which the program takes it as the boundary of the seed which is not a good results like in the picture below. How can i make the program ignore dents. Is masking the seeds a good option in this case.
I converted the image from BGR color space to HSV color space.
Then I extracted the hue channel:
Then I performed threshold on it:
Note:
Whenever you face difficulty in certain areas try working in a different color space, the HSV color space being most prominent.
UPDATE:
Here is the code:
import cv2
import numpy as np
filename = 'seed.jpg'
img = cv2.imread(filename) #---Reading image file---
hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) #---Converting RGB image to HSV
hue, saturation, value, = cv2.split(hsv_img) #---Splitting HSV image to 3 channels---
blur = cv2.GaussianBlur(hue,(3,3),0) #---Blur to smooth the edges---
ret,th = cv2.threshold(blur, 38, 255, 0) #---Binary threshold---
cv2.imshow('th.jpg',th)
Now you can perform contour operations to highlight your regions of interest also. Try it out!! :)
ANOTHER UPDATE:
I found the contours higher than a certain constraint to get this:
There are countless ways for image segmentation.
The simplest one is a global threshold operation. If you want to know more on other methods you should read some books. Which I recommend anyway befor you do any further image processing. It doesn't make much sense to start image processing if you don't know the most basic tools.
Just to show you how this could be achieved:
I converted the image from RGB to HSB. I then applied separate global thresholds to the hue and brightness channels to get the best segmentation result for both images.
Both binary images were then combined using a pixelwise AND operation. I did this because both channels gave sub-optimal results, but their overlap was pretty good.
I also applied some morphological operators to clean up the results.
Of course you can just invert the image to get the desired black background...
Thresholds and the used channels of course depend on the image you have and what you want to achieve. This is a very case-specific process that can be dynamically adapted to a limited extend.
This could be followed by labling or whatever you need:
Here i have one RGB image where i need want extract plane of intensity.
I have tried HSL, in this i took L Luminosity but its not similar with Intensity, and tried RGB2GRAY but this also little bit similar but not actual.
so is there any special code to get intensity of the image? or is there any calculation of Intensity?
Try to use BGR2GRAY(and so on - BGR2HSL etc) instead of RGB2GRAY - OpenCV usually use BGR channel order, not RGB.
The default format of RGB in OpenCV is BGR. So, you can get the intensity of your image using OpenCV like below:
intensity_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2HSV);
intensity_image[:,:,2] is the value image of your original image
Hope this helps.