How can I make a vector that counts pixels of a binary image??

9 views (last 30 days)
Hi everyone!
I have a matlab script that is used for motion detection. Basically you take a video and divide it into its frames, then the algorithm takes these frames, convert them in grayscale and creates a new video which is made of binary images that show if there's something moving in the pictures. Now I'd like to plot two histograms, one for each axis. Basically I would like to count for each row and column the number of white pixels (the ones that detect movement) and show this number at the sides of the binary video in a histogram that includes all the rows/columns at one time. This operation has to be performed for each frame of this video, so I can show how many pixels are involved in detecting motion.
I think that I should use a for statement loop, but I struggle to chose the correct data structure. The pixels I want to count are store in a variable called HOT_MAT
This is a link where you can find the code and the video I used: https://drive.google.com/open?id=0B6BDW6BM-8ntMmVmM3dCdzlESzg
Thanks you for any help you can provide
Could anyone show me how to do that, or give me some hints about this issue?
  1 Comment
Andrea Zuccotto
Andrea Zuccotto on 9 Dec 2016
This is actually the correct link: https://drive.google.com/drive/folders/0B6BDW6BM-8ntTklnUW0xa0RaSWs?usp=sharing

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 9 Dec 2016
To sum the white/true/1 pixels in columns and rows do this:
columnCounts = sum(binaryImage, 1); % Counts along each column.
rowCounts = sum(binaryImage, 2); % Counts along each row.
  2 Comments
Andrea Zuccotto
Andrea Zuccotto on 9 Dec 2016
OK, but then how can I use this variables to show an histogram?
Image Analyst
Image Analyst on 9 Dec 2016
What histogram? You have only two values in a binary image: 0 and 1. If you want you can make a bar chart out of the counts of the 0's and 1's:
bar([numColumns-columnCounts, columnCounts]);
bar([numRows-rowCounts, rowCounts]);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!