Removing noise from binary iamge

조회 수: 17 (최근 30일)
Adrian Lim
Adrian Lim 2018년 7월 8일
댓글: PBM 2020년 5월 29일
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월 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일
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
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개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by