color-凯发k8网页登录
acquire an image and perform image analysis to find small objects, count them, and differentiate them by color.
hello, and welcome. in this video, we will use image acquisition toolbox™ to capture images into matlab®. and we will then perform image analysis and other operations using image processing toolbox™. as an example, i have set up my camera to capture images of candies of different colors. we will determine the total number of candies in the image and count the number of candies of a certain color.
in this example, i will perform various image processing algorithms, such as thresholding, morphological operations, and color segmentation on the acquired images. the first step is to connect my camera to matlab. to see if matlab recognizes that my camera is available, i use the imaqhwinfo command to get a list of the hardware adapters and specific devices available on my computer. the camera that i currently have connected is accessible through the winvideo adapter. so i use the imaqhwinfo command to obtain its device id.
with this information, i can use the video input command to create an instance of an image acquisition object that can acquire video from my camera. using this video input object, i can bring up a preview window for my captured video. i then use the getsnapshot command to capture one image frame from my acquired video. i can display this image frame using the imshow command inside matlab. let me dock this image frame here.
let us first identify all objects in the image using thresholding. so i separate the r, g, and b compoments of my image and compute a threshold value for each of them separately using the graythresh command. i then threshold each of those components separately using the im2bw command and then combine them together to have a binary image with clearly identified objects.
to remove any artifacts in the image, i use morphological operations such as imfill to remove any holes and imclearborder to remove any extraneous objects lying on the border. it is now very easy to distinctly count the number of objects in my image. i use the bwlabel command to uniquely label each object and count the total number of objects in the image.
to robustly select candies of a certain color, we need to account for variation in color values across an object caused by problems such as non-uniform lighting conditions and camera noise. so i need to construct an image that replaces the actual rgb values with the median color of each candy.
to do this, i use logical indexing to get only those pixels that i want and then calculate their median. for instance, i can logically index into the images label matrix and extract only those pixels with a label of 1. let me show an example here.
i can then calculate the median of the extracted pixels that belong to this segmented region. so in this for loop, i have thus computed the median values for all three color planes for each label. and at the end of the loop, i recombine the color components to know the medium color value for each candy.
using the impixelinfo command from the image processing toolbox, i can see the median r, g and b values that i just computed for each candy. i now want to select the desired color and count the number of candies for that particular color. since i already had the median color of each labeled region, i need to simply find the regions that have a median color close to the selected color.
for color-based selection, it is better to work with a lab color space, because it separates out luminescence information from color information. the euclidean distance between color values in this space is a more effective measure for color similarity than in the rgb color space. so i've used the makecform and the applycform comments to convert my image and the selected color from rgb to lab space.
from this, i can keep the a and b components as i don't really need any luminescence information here. to find regions with the same color, i first calculate the euclidean distance between the color values using the hypot command with the a and b components. i then use an appropriate threshold hold value to choose only those regions that lie close to the selected color. i then can use the bwlabel command to obtain account of the chosen regions.
so this demo illustrated how image processing toolbox and image acquisition toolbox can be combined to perform image analysis operations for a live feed of images. taking this example a step further, you could add a gui with guide or even build a standalone executable with matlab compiler™. for more image acquisition and processing demos, please visit the product pages on our web site. thank you.
featured product
image processing toolbox
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 mathworks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- (español)
- (english)
- (english)
欧洲
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
亚太
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)