You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
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 view (last 30 days)
Show older comments
I want to know how to color certain region in video in matlab
2 Comments
Aarach Sap
on 14 Sep 2021
I want to color the two hands to different color . Is it possible in matlab?
Answers (1)
Image Analyst
on 13 Sep 2021
See my attached demo where I find a green Sharpie in the video. Adapt as needed.
17 Comments
Aarach Sap
on 14 Sep 2021
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
on 14 Sep 2021
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
on 15 Sep 2021
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
on 15 Sep 2021
@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
on 16 Sep 2021
Edited: Aarach Sap
on 16 Sep 2021
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
on 16 Sep 2021
@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
on 17 Sep 2021
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
on 17 Sep 2021
- "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
on 22 Sep 2021
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
on 22 Sep 2021
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
on 24 Sep 2021
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
on 24 Sep 2021
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
on 27 Sep 2021
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
on 27 Sep 2021
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
on 29 Sep 2021
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
on 29 Sep 2021
@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:
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)