I wants to detect lines from an image with black line drawing over white papers.
It could be easy if its ideal 'black and white', using histogram threshold would do.
But, as the image attached shows, some lines (e.g. in the light red circle) are in gray lighter than the shades (e.g. in the dark red circle). So some shades are obtained before light lines using histogram threshold.
Is there any ideas to divide lines from shades with some 'knowledge'? Thanks!
Edit:
Here are the raw images, a bit small because they are of original resolution.
Thanks :-)
I would add another method using Gaussian blur other than erosion+dilation, for your reference:
file='http://i.stack.imgur.com/oEjtT.png';
I=imread(file);
h = fspecial('gaussian',5,4);
I1=imfilter(I,h,'replicate');
h = fspecial('gaussian',5);
I2=imfilter(I,h,'replicate');
I3=I1-I2;
I3=double(I3(:,:,1));
I3=I3.*(I3>5);
imshow(I3)
Related
I'm trying to use a render pass descriptor to draw two grayscale textures. I am drawing a black square first, then a light gray square after. The second square partially covers the first.
With this setup, the light gray square will always appear in front of the black square because it was drawn most recently in the render pass. However, I would like to know if there is a way to draw the black square above the light gray one based on its brightness. Since the squares only partially overlap is there a way to still have the black square appear on top simply because it has a darker pixel value?
Currently it looks something like this, where the gray square is drawn second so it appears on top.
What I would like is to be able to still draw the gray square second, but have it appear underneath based on the pixel brightness, like so:
I think MTLBlendOperationMin will do what you want: https://developer.apple.com/documentation/metal/mtlblendoperation/mtlblendoperationmin?language=objc
I am currently working on a lane detection project, where the input is an RGB road image "img" from a racing game, and the output is the same image annotated with drawn colored lines on detected lanes.
The steps are:
Convert the RGB image "img" to HSL image, then use a white color mask on it (white lanes only are expected in the image) with a white color range to discard any parts of the image with colors outside this range (put their values as zeros), let the output of this step by "white_img".
convert "white_img" to Grayscale producing "gray_img".
Apply Gaussian blurring to "gray_img" to make edges smoother, so less noisy edges can be detected, producing "smoothed_img".
Apply edge detection on "smoothed_img", producing "edge_img".
Crop "edge_img" by selecting a region of interest ROI, which is approximately within the lower half of image, producing "roi_img".
Finally, apply Hough transform on "roi_img" to detect the lines which will be considered as the detected lanes.
The biggest problems I am facing now are the brightness change and shades on lanes. For a dark image with shades on lanes, the lanes color can become very dark. I tried to increase the accepted white color range in step 1, which worked well for this kind of images. But for a bright image with no shades on lanes, most of the image is not discarded after step 1, which produces an output containing many things irrelevant to lanes.
Examples of input images:
Medium brightness without shades on lanes
Low brightness with shades on lanes
High brightness without shades on lanes
Any help to deal with these issues will be appreciated. Thanks in advance.
I have two questions:
1) I have segmented an image from the background and the result is a colored circle with a black background. When I do histogram using calcHist(), is the result will be the histogram of the colored circle or it will include even the black background.
2) After calculating the histogram for lab image for each channel l, a, and b and calculate the mean for each histogram, it gave me same mean for each channel while the standard deviation and the mode are different. Is this correct or I am doing something wrong.
Any help would be appreciated.
I have binarized an image and calculate its black and white pixels. After pixel calculation, calculate the ratio of black pixels i.e. R= (no:of black pixels/ no: of white pixel+no: of black pixels)*100. I have to used this result to declare an eye is open or closed if R>20% then eye is in open state else closed. But when I calculate this ratio it is not coming what i want. I think there might be some error in calculation of black and white pixel, due to unwanted black region in image or might be problem in thresholding an image. I am using Otsu's method for thresholding image.
While finding on this topic I also try `openInput=bwareaopen(bw, 80) but this is not work well to remove unwanted black area. Kindly help me out in removing the unwanted area.
close all
clear all
I=imread('op.jpg');
I=rgb2gray(I);
thres_level=graythresh(I); % find the threshold level of image
bw=im2bw(I,thres_level); % converts an image into binary
figure, imshow(bw);
totnumpix=numel(bw); % calculate total no of pixels in image
nwhite_open=sum(bw(:)); % calculate the black pixels in image;
nblack_open=totnumpix-nwhite_open; %calculate white pixels in image;
R=(nblack_open/(nblack_open+nwhite_open))*100
The area opening erase areas having a surface smaller than the parameter you enter. In your case, it will not likely help.
I think that the black/white ratio is not the solution. I would either:
Detect the iris (multiple effective papers/posts on the subject, mainly using hough transform), and if the detection fails, then the eye is closed.
If you have the original color image, then use a skin detection (simple color thresholding in the HSV color space). Because the ratio of skin you will determine when the eye is closed.
Anyone know any algorithm to non-linearly change lightness using HSI model?
I am currently doing something like this.
new intensity = old intensity^(1/4)
It increases lightness of dark color more than lightness of bright color.
The problem is that before enhancement, if I have some pixels look like black color because of very low lightness, their lightness increase after enhancement and their actual colors appear which make black area of photo has different colors(eg: grey,blue). I have tried quite a few ways to solve it by lowering new lightness of black spot but I have no luck so far.
Is there anyway to solve it or is there better algorithm? The problem is only with color which appear to be black before enhancement.
Please help. Thank a lot.
The HSI values of dark pixels are usually degenerate. This is because, for example, a fully saturated maximally-dark blue = black, is identical in appearance to a completely de-saturated (grey) pixel at its darkest = black (this is the reason the 3D space shape usually has a pointed tip at the degenerate/singular colors).
You should not enhance pixels under a certain threshold value, or alternatively, use some weighting function that inhibits enhancement at the very dark values.