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

2 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 2 Feb 2019
Edited: Image Analyst on 2 Feb 2019
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 Comments
Image Analyst
Image Analyst on 21 Feb 2019
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 on 23 Feb 2019
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

Sign in to comment.

More Answers (1)

sangeetha N
sangeetha N on 8 Feb 2019
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?

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!