1903 1

[Weka及其他] MATLAB课程:代码示例之Image Processing and Computer Vision(二) [推广有奖]

企业贵宾

巨擘

0%

还不是VIP/贵宾

-

威望
4
论坛币
624047 个
通用积分
147.0356
学术水平
918 点
热心指数
988 点
信用等级
842 点
经验
398722 点
帖子
9795
精华
48
在线时间
17322 小时
注册时间
2014-8-19
最后登录
2022-11-2

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

MATLAB课程:代码示例之Image Processing and Computer Vision(二)


Correcting Nonuniform Illumination


This example shows how to correct nonuniform illumination in an image to make it easy to identify individual grains of rice in the image. You can then learn about the characteristics of the grains and easily compute statistics for all the grains in the image.


Step 1: Read ImageI = imread('rice.png');imshow(I)


Step 2: Use Morphological Opening to Estimate the Background

Notice that the background illumination is brighter in the center of the image than at the bottom. Use imopen to estimate the background illumination.

background = imopen(I,strel('disk',15));% Display the Background Approximation as a Surfacefiguresurf(double(background(1:8:end,1:8:end))),zlim([0 255]);ax = gca;ax.YDir = 'reverse';


Step 3: Subtract the Background Image from the Original ImageI2 = I - background;imshow(I2)


Note that step 2 and step 3 together could be replaced by a single step using imtophat which first calculates the morphological opening and then subtracts it from the original image.

I2 = imtophat(I,strel('disk',15));

Step 4: Increase the Image ContrastI3 = imadjust(I2);imshow(I3);


Step 5: Threshold the Image

Create a new binary image by thresholding the adjusted image. Remove background noise with bwareaopen.

bw = imbinarize(I3);bw = bwareaopen(bw, 50);imshow(bw)


Step 6: Identify Objects in the Image

The function bwconncomp finds all the connected components (objects) in the binary image. The accuracy of your results depend on the size of the objects, the connectivity parameter (4,8,or arbitrary), and whether or not any objects are touching (in which case they may be labeled as one object). Some of the rice grains in bw are touching.

cc = bwconncomp(bw, 4)


cc =     Connectivity: 4       ImageSize: [256 256]      NumObjects: 95    PixelIdxList: {1x95 cell}


Step 7: Examine One Object

Each distinct object is labeled with the same integer value. Show the grain that is the 50th connected component.

grain = false(size(bw));grain(cc.PixelIdxList{50}) = true;imshow(grain);


Step 8: View All Objects

One way to visualize connected components is to create a label matrix and then display it as a pseudo-color indexed image.

Use labelmatrix to create a label matrix from the output of bwconncomp. Note that labelmatrix stores the label matrix in the smallest numeric class necessary for the number of objects.

labeled = labelmatrix(cc);whos labeled


  Name           Size             Bytes  Class    Attributes  labeled      256x256            65536  uint8              


In the pseudo-color image, the label identifying each object in the label matrix maps to a different color in the associated colormap matrix. Use label2rgb to choose the colormap, the background color, and how objects in the label matrix map to colors in the colormap.

RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');imshow(RGB_label)


Step 9: Compute Area of Each Object

Each rice grain is one connected component in the cc structure. Use regionprops on cc to get the area.

graindata = regionprops(cc,'basic')


graindata = 95x1 struct array with fields:    Area    Centroid    BoundingBox


To find the area of the 50th component, use dot notation to access the Area field in the 50th element of graindata structure array.

graindata(50).Area


ans =   194


Step 10: Compute Area-based Statistics

Create a new vector grain_areas, which holds the area measurement for each grain.

grain_areas = [graindata.Area];


Find the grain with the smallest area.

[min_area, idx] = min(grain_areas)grain = false(size(bw));grain(cc.PixelIdxList{idx}) = true;imshow(grain);


min_area =    61idx =    16


Step 11: Create Histogram of the Areanbins = 20;figure, hist(grain_areas,nbins)title('Histogram of Rice Grain Area');




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Processing processI Computer MATLAB课程 compute MATLAB课程 代码示例 ImageProcessingandComputerVision CorrectingNonuniformIllumination

本帖被以下文库推荐


https://www.cda.cn/?seo-luntan
高薪就业·数据科学人才·16年教育品牌
沙发
全球之行heart 在职认证  发表于 2016-3-14 11:58:08 |只看作者 |坛友微信交流群
果然有用,太赞了!

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 13:23