# Quantifying red in a recorded video

2 ビュー (過去 30 日間)
Jonathan 2023 年 5 月 31 日

Complete novice. I am looking to quantify the percentage area of red for each frame of a stored video. Any suggestions how I can do that? I am aware I will have to define "red" and would also appreciate any advice in this regard. Thank you!

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

### 回答 (2 件)

Ashutosh 2023 年 6 月 1 日
Hi,
You can use the VideoReader function to read a video file to MATLAB, and then use its various properties and object functions to access each frame individually as an image.
Then, for each frame, perform some preprocessing to bring all pixels down to a standard indication of redness, by subtracting the grayscale values from the red channel. Find the pixels that have Red intensity higher than a certain threshold value, and count these instances. Finally, find the percentage of the total number of pixels.
The below code should work:
redPixelCount = 0;
thresholdValue = 100;
frameCount = vid.NumFrames;
red = zeros(1,frameCount);
i=1;
while hasFrame(vid)
redChannel = imsubtract(frame(:,:,1), rgb2gray(frame));
redAreaPercent = (redPixelCount / numel(frame(:,:,1))) * 100;
red(i) = redAreaPercent;
i = i+1;
end
The thresholdValue is what may be used to define the "red", in your instance. From some trial and error, I found out that something between 90 and 160 should be fine.
You read more about the Image Processing functions in the MATLAB documentation.
Hope this helps!
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

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

Image Analyst 2023 年 6 月 1 日
See attached demo. I track a green Sharpie marker. You can easily adapt it to track something red in the video.

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

### カテゴリ

Help Center および File ExchangeDisplay Image についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by