Hello, there are problems that I faced during extracting the background from the image below. Im using image>background to extract them and change it to a binary image. The binary image shows too much noise that I could not count the number of cars in the image. Is it possible to filter out the image and have only the cars left in the binary image? Could it be the method of extracting the backgrounds are wrong or filtering would work? Thanks in advance.

7 件のコメント

jonas
jonas 2018 年 7 月 8 日
編集済み: jonas 2018 年 7 月 8 日
Probably subtracting the background image from the ones with cars would make it easier to count. I got the attached figure by using the low-res image you provided. With the source images the results would be much better.
Adrian Lim
Adrian Lim 2018 年 7 月 8 日
Niceee! Thank you so much! But is there more filtering that could work even better to remove the backgrounds? Thank you so much!
jonas
jonas 2018 年 7 月 8 日
編集済み: jonas 2018 年 7 月 8 日
No problem! If you upload the images then I can give it a try. It depends on the features of the noise.
Adrian Lim
Adrian Lim 2018 年 7 月 8 日
Here are the pictures. I also wonder if the effect will be affected if i moved the camera accidentally by a little. Thanks in advance.
Florian Morsch
Florian Morsch 2018 年 7 月 9 日
If you move the cam a little in between the shots then of course it will affect the result. If you substract the background from the car-image and you have moved the cam for only one mm it can change for example 10 pixel to the left (or right).
This means: your background has a white stripe on the street. In the car-image this white stripe is 10 pixel to the left. If you substract them now you have a significant difference. And thats not only for one pixel but the whole image. If you use that method you should try and get the shots without moving the cam or the object at all.
Also light changes can affect the result. If you have normal light for the background shot and then someone opens a curtain on the other side of the room, even if the light coming in will not directly hit the object it could affect your images. (again, depending on the use its not that much, but it can make a difference, had that exact problem with color detection, as soon as the door was open my color "changed" and was labeled incorrect)
jonas
jonas 2018 年 7 月 9 日
編集済み: jonas 2018 年 7 月 9 日
I didn't have much luck with noise-removal. Best I could do for a single image was this.
I2=imread('Frame.jpg');
BW1 = im2bw(I2, 0.1);
BW2 = im2bw(I2, 0.5);
diff=BW1-BW2;
diff(diff<=0)=0;
imshow(~diff)
Which I got simply by playing with the threshold values.
If you use the reference (background) image, then moving the camera will affect the result quite a bit yes. You will probably get the best result if the camera remains steady, but you can also adjust the image for camera displacement quite easily. If you want to use this method, then I suggest you add some reference points (e.g. some bright markers) to your physical models.
Adrian Lim
Adrian Lim 2018 年 7 月 9 日
Thank you for the answers,guys! I'll try a little bit on my own to see the result! Hope I could get the results and count the cars.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2018 年 7 月 9 日
編集済み: Matt J 2018 年 7 月 9 日

0 投票

This might help. Basically, the idea is to quantize the background and develop a mask that gets rid of a lot of the extraneous detail around the cars.
C=im2double(imread('Cars.jpg'));
B=im2double(imread('Background.jpg'));
maxchan=max(B,[],3);
threshmax = multithresh(maxchan,4);
Qmax=imquantize(maxchan,threshmax);
bw=bwareafilt( Qmax==2,1);
bw=imclose(bw,strel('disk',10));
D=rgb2gray(bw.*(C-B));
thresh=multithresh(D,2);
result=bwareafilt( imquantize(D,thresh)>1, [10,inf]);
imshow(result)

9 件のコメント

Adrian Lim
Adrian Lim 2018 年 7 月 9 日
Thank you for the answer! This helped getting rid of the background but is it possible to count the cars from the image above? I'm not sure how to change the image into a binary image and count the cars.
Matt J
Matt J 2018 年 7 月 9 日
編集済み: Matt J 2018 年 7 月 9 日
Now it's binary.
As for counting, I assumed you had a way of doing that after getting rid of the binary noise. That's presumably why you asked about denoising.
Adrian Lim
Adrian Lim 2018 年 7 月 9 日
Yes I do, Im using drawing boundaries around the object and count the number of boundaries which I learned from a website. But from the binary image, the white colours which are not in one piece would not allow drawing boundaries. Is there anything that I could try like removing small pixels by bwareaopen or any other ways? I'm quite new in MATLAB so I have a little knowledge in this. I could do research on counting them. Thank you so much for the help!
jonas
jonas 2018 年 7 月 9 日
You may be interested in bwconncomp for finding connected regions
You should probably accept this answer and open a new question on detecting objects. I also assumed this was specifically about noise-removal.
Matt J
Matt J 2018 年 7 月 9 日
編集済み: Matt J 2018 年 7 月 9 日
Here's a better version. The separation between the car blobs and suppression of the lane markers should improve once you fix up the camera perspectives and lighting as suggested by Florian.
C=im2double(imread('Cars.jpg'));
B=im2double(imread('Background.jpg'));
maxchan=max(B,[],3);
threshmax = multithresh(maxchan,4);
Qmax=imquantize(maxchan,threshmax);
bw=bwareafilt( Qmax==2,1);
bw=imclose(bw,strel('disk',10));
T=bw.*(rgb2hsv(C)-rgb2hsv(B));
D=max(T(:,:,2:3),[],3);
thresh=multithresh(D,2);
M=imclose( imquantize(D,thresh)>1, strel('disk',10));
M=bwpropfilt(M ,'Perimeter', 12);
result=bwpropfilt(M ,'Solidity', 8);
imshow(result)
Adrian Lim
Adrian Lim 2018 年 7 月 9 日
Thank you so much for the help! It helped me a lot! I'll start a new question if there is anything I do not understand.
PBM
PBM 2020 年 5 月 23 日
Hi Matt,
I am a beginner at Image Processing --- I read through your code and commented on four points that I wasn't sure the conceptual reason behind it (of course, it works - I am just bolstering my understanding). Could you take a look below and advise if I am understanding the intent of those lines correctly?
threshmax = multithresh(maxchan,4); %One threshold for the cars, one for background, one for road markings... but five thresholds here due to multiple thresholds for the cars?
bw=bwareafilt( Qmax==2,1); %this seems to be only looking for the largest blob in the second threshold, did you select the second threshold just by trial and error as the threshold with most noise?
D=max(T(:,:,2:3),[],3); % This is taking the higher value between the saturation/brightness value of the image as hue can be misleading, I am assuming
M=bwpropfilt(M ,'Perimeter', 12); %How come the 12 largest perimeters? Could we not stop at just six for six cars? Although I see that 8 'most' convex objects are extracted next, didn't think any other perimeters would be more than the cars
Matt J
Matt J 2020 年 5 月 23 日
Hi PBM,
It's been a few years since I posted this solution, but as I recall, most of these parameter selections were trial and error. In a scenario where you need to be more general, most people nowadays would probably apply deep learning object recognition techniques.
The possibility of dropping the Perimeter search from the 12 largest to the 6 largest is something you could test by running the code. I dimly remember that the boundaries of the road, and maybe some other objects in the image had the largest perimeters, and so you needed a threshold larger than 6 so as not to exclude any of the cars. It's also possible that I was allowing for the case where more than 6 cars were present in the field of view.
PBM
PBM 2020 年 5 月 29 日
Hi Matt,
Thanks for your response. I just did something similar and yes it was trial and error. I will attempt deep learning recognition techniques for a more general solution... thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2018 年 7 月 8 日

コメント済み:

PBM
2020 年 5 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by