How do I subtract the following two images and determine the number of pixels in a certain section of an image?

조회 수: 11 (최근 30일)
pdms1.jpgpdms2.jpg
How would I subtract the following two images of the same size? My goal is to subtract and remove the purple section so I can determine the number of pixels in the gray section on the lower left (below the black line). My problem is that the purple section in both images aren't exactly the same, since they are different frames of a video. Would it be easier to just focus on the second image using some image segmenting or edge detection technique? Please help me out.

채택된 답변

Image Analyst
Image Analyst 2019년 2월 2일
편집: Image Analyst 2019년 2월 2일
Definitely not edge detection. What I'd do is use the Color Thresholder App on the Apps tab of the tool ribbon and segment in HSV color space. Then export the function to create a mask. Then you can use bwareafilt() to extract the largest blob or blobs of certain sizes.
[EDIT]
OK, since a lot of time has gone by and you still haven't responded, I'm assuming you couldn't quite get it. So I'm attaching a script that gives you the area.
area = 35389 pixels
Adapt as needed.
0001 Screenshot.png
  댓글 수: 6
Image Analyst
Image Analyst 2019년 2월 21일
No, don't subtract them after they've been binarized. If you have a good baseline/reference color or gray scale image, subtract that from each frame before doing color segmentation to form the binary image mask of the "test" frame.
Jialu Wang
Jialu Wang 2019년 2월 23일
Hi so I've tried subtracting the pink background image with a frame that has the gray moving in, but keep getting something that looks like this. What am I doing wrong? I'm not exactly sure how to apply a median filter--is that the issue? Should I convert to HSV space first?
Also what would a KNN or SVM code look like? Will the colour thresholding code you posted originally still work after I do the image subtraction?
subtract.PNG

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

sangeetha N
sangeetha N 2019년 2월 8일
What to do if it was a video file? How to get the subtracted image?
If the objects are stationary,then after subtracting the input image and adaptive background image, I am getting number of objects as zero.How to solve this problem?

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by