How can I color certain part of video (suppose hand) and detect the color using color thresholding?The latter part is fine . Plz help me on this.
1 次查看(过去 30 天)
显示 更早的评论
I want to know how to color certain region in video in matlab
2 个评论
回答(1 个)
Image Analyst
2021-9-13
See my attached demo where I find a green Sharpie in the video. Adapt as needed.
17 个评论
Aarach Sap
2021-9-14
Thank you! I have already checked your demo.I would like to color two hands differently and track the color.
Is it possible?Plz help me.
Image Analyst
2021-9-14
Yes it's possible. Just do your image segmentation to get two blobs (hands). Then label them with bwlabel() and then use label2rgb() to apply colors. Use regionprops(binaryImage, 'Centroid') to track the centroids.
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, originalImage, 'all');
numberOfBlobs = size(blobMeasurements, 1);
Aarach Sap
2021-9-15
Thank you for your time! I also noticed label2rgb() is there to apply colors. However, there is still error on regionprops section.
i.e.,blobMeasurements = regionprops(labeledImage, originalImage, 'all');
Actually, my originalImage does not include colored hands,both are same as skintone. Is it bcoz of that?
Image Analyst
2021-9-15
@Aarach Sap, it depends on what youre measuring. Show me your line of code for regionprops(). If you're measuring shape only things then you don't need the gray scale image "originalImage". If you're measuring intensity things, like MeanIntensity, then you'll need to include a gray scale image (usually uint8). You didn't pass in the full RGB color image for originalImage, did you? Because that would be a huge mistake.
Also, you forgot to read the posting guidelines
which means you did not know that you need to include your image and code, as well as the complete error message. If you need more help, please attach them after reading the link above.
Aarach Sap
2021-9-16
编辑:Aarach Sap
2021-9-16
Sorry, for making you in trouble and Thank you! I am able to do regionprops from your code. Here is the code. I got the centriods of all region of interest. However, I want to track the centriods according the colors shown not by area. As I am using in video the area of region of interest may change, so I want to track the same color and get the centriod.
Image Analyst
2021-9-16
@Aarach Sap, you forgot to attach the A.png image. Also, this program just looks at a single image, not multiple frames of a video, and does no tracking.
Plus, I have not delivered a full blown tracking app. I track just one blob in the video, not multiple. Having multiple blobs increases the complexity enormously if it's to take into account blobs entering and leaving the fielw of view, blobs overlapping, blobs changing shape or color, etc.
Aarach Sap
2021-9-17
The program I attached is only for Image. Any image of a person showing hands can be used. However, I want to apply for video. Is it possible to fill different colors to different blobs? or Can we set the colors in label2rgb or sth like that. I am still not getting to the point. Plz suggest me!
Image Analyst
2021-9-17
- "Is it possible to fill different colors to different blobs?" Yes, with bwlabel() and label2rgb().
- "Can we set the colors in label2rgb or sth like that?" Yes, you can specify the colors used to label the blobs, like if you want jet instead of hsv, do
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'jet');
Aarach Sap
2021-9-22
Thank you for your reply! But this method change the colors of two blobs i.e.hands, in various colors in different frames of a video. So it is not possible track those blobs by coloring them. Actually, I need the centriod of blobs, which I already get it and can display it. Why is it difficult to write those points( eg.this point is for left blob)? Is there any other way? I thought coloring will do but actually dont. Plz suggest me if there are any idea regarding this.
Image Analyst
2021-9-22
You can certainly detect two colored objects in a frame, and can produce a binary image (mask) from them. This is usually done by color segmentation (thresholding some image). Then you can detect the centroids of the blobs using regionprops(). You can log those centroids to an array. But all of that is done by what I said -- thresholding and assignment -- it's not done by coloring the blobs. However, once the hands have been detected (mask generated) and tracked (centroid locations logged), it's possible to colorize the hands (e.g. left=blue, and right=red) using label2rgb(). That colorizing process is not called "tracking". The tracking was done when you thresholded, found the centroids, and saved their location, NOT by colorizing the blobs after you found them.
Aarach Sap
2021-9-24
I dont have two colored objects. I have only one color i.e. skin color of hands . I want to track the centriod of two hands and write this centrod is for left hand and other is for right hand. I understand what you explain. Thank you for that.
Image Analyst
2021-9-24
So you have two colored objects that have roughly the same color. You can detect both of those with the same color segmentation or motion segmentation algorithm. Then call
mask = bwareafilt(mask, 2);
to extract the two largest blobs, which should be the hands. Then do
props = regionprops(mask, 'Centroid');
xy = vertcat(props.Centroid);
to get the centroid of each hand.
Aarach Sap
2021-9-27
Thank you Image Analyst for the continuous response! I really appreciate your help. I have tried this one.
mask = bwareafilt(mask, 2);
[labeledImage, numberOfBlobs] = bwlabel(mask);
%for the first blob 1
blobMeasurements= regionprops(labeledImage==1, 'BoundingBox', 'Centroid','Orientation');
Centriod_of1= vertcat(blobMeasurements.Centroid);
However, if the hand is crossed then it will take other hand as first blob why? I just want to track the hand movement.
Image Analyst
2021-9-27
Tracking is a difficult thing. There are problems with tracked objects overlap, or enter or leave the field of view. I did not write a full, turnkey tracking app that handles all kinds of situations. You can search the internet for tracking apps. I know I listed a bunch of such tracking websites here this summer so you can look for that list.
Aarach Sap
2021-9-29
Yes, tracking is difficult. Anyways thank you for your earlier suggestions. I learned so many things. Do you suggest any best tracking website?
Image Analyst
2021-9-29
@Aarach Sap We use the tracking program from Noldus. I believe it's the best out there. It's expensive but it may save you much time over developing it yourself.
Other, cheaper tracking programs are listed in my Answer here:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)