質問

I'm trying to implement this paper on [Traffic Light Detection and Recognition]. So far I've found the blobs in the image (using regionprops) and then checked the ones that fulfill the criteria:

  1. Dimension Ratio
  2. No holes
  3. Convex approximation

I'm done with Dimension Ratio and No holes.

The input image I used is: Original Image. I've applied the top hat operator imtophat, binarized it using Otsu thresholding method graythresh, and obtained this image with the blobs (blobs that fulfilled the dimension Ratio & No holes criteria are included in image).

Now I'm stuck with the Convex Approximation, I'm trying to find the blobs that are convex enough to be accepted as a candidate for the traffic light. How should I check if the blobs detected are convex enough to be accepted?

役に立ちましたか?

解決

I am afraid that I cannot get good results from the image after your processing (the 2nd image link). I tried to use a slightly different method to extract the red light in your original image. Hopefully it can help you a little bit. First of all, you may need to convert the RGB to the Lab space. Actually it is very suitable to handle the image in that space, and some operations can maximize the difference between red and green light. Since there is only a red light in your image, I won't go that complicated. I only used b-channel for further processing.

file='https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-prn1/1524779_10153642995125182_414999862_n.jpg';
I=imread(file);Irgb=I;

colorTransform = makecform('srgb2lab');
I = applycform(I, colorTransform);
b = I(:,:,3);
I=double(b);
Imin=min(I(:));
Imax=max(I(:));
I=(I-Imin)/(Imax-Imin);
imshow(I)

Will get you:

enter image description here

Next, we remove the line/square structure, indeed they have very strong intensity that may impact our further result:

se = strel('line',20,0);
I = imtophat(I,se);
figure,imshow(I)

You will have:

enter image description here

In the next step we are trying to find out the local maximum value in the image:

roi=20;thresh=0.5;
local_extr = ordfilt2(I, roi^2, ones(roi)); 
% Get local maxima and reject candidates below a threshold
result = (I == local_extr) & (I > thresh);
% Get indices of extrema
[r, c] = find(result);
% Show them
figure;imshow(I, []); hold on;
plot(c, r, 'r.');hold off

You will see:

enter image description here

In fact the red light has already been tagged (I saw another red point in your original image, but I assume that is a walking sign with the red hand shape instead of a circle red light, so herein I won't consider that part.)

Finally we use the regionprops with the eccentricity property, and find out the region with the least eccentricity, that will look more alike a circle shape:

for i=1:length(c)

    I1=I(r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi);
    I1=im2bw(I1);

    labeledImage = bwlabel(I1);
    blobMeasurements = regionprops(labeledImage,'eccentricity'); 
    if isempty(blobMeasurements)
        e(i)=Inf;
    else
        e(i)=blobMeasurements.Eccentricity;
    end

end
[a,idx]=min(e);

res = zeros(size(I,1),size(I,2),3); 
i=idx;
res( r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi ,1) = Irgb(r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi,1);
res( r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi ,2) = Irgb(r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi,2);
res( r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi ,3) = Irgb(r(i)-roi:r(i)+roi,c(i)-roi:c(i)+roi,3);
figure,imshow(uint8(res))

The result:

enter image description here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top