QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2595|回复: 1
打印 上一主题 下一主题

备战美赛吧 matlab 2013a 照度不均匀校正

[复制链接]
字体大小: 正常 放大

3503

主题

538

听众

5990

积分

  • TA的每日心情
    开心
    2017-2-7 15:12
  • 签到天数: 691 天

    [LV.9]以坛为家II

    社区QQ达人 元老勋章 发帖功臣 新人进步奖 优秀斑竹奖 金点子奖 原创写作奖 最具活力勋章 助人为乐奖 风雨历程奖

    群组2013年国赛赛前培训

    群组2014年地区赛数学建模

    群组数学中国第二期SAS培训

    群组物联网工程师考试

    群组2013年美赛优秀论文解

    跳转到指定楼层
    1#
    发表于 2013-7-30 14:40 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    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 Image
    1. I = imread('rice.png');
    2. imshow(I)
    复制代码
    ipexrice_01.png
    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.
    1. background = imopen(I,strel('disk',15));

    2. % Display the Background Approximation as a Surface
    3. figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
    4. set(gca,'ydir','reverse');
    复制代码
    ipexrice_02.png


    Step 3: Subtract the Background Image from the Original Image
    1. I2 = I - background;
    2. imshow(I2)
    复制代码
    ipexrice_03.png
    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 Contrast
    1. I3 = imadjust(I2);
    2. imshow(I3);
    复制代码
    ipexrice_04.png

    Step 5: Threshold the Image

    Create a new binary image by thresholding the adjusted image. Remove background noise with bwareaopen.
    1. level = graythresh(I3);
    2. bw = im2bw(I3,level);
    3. bw = bwareaopen(bw, 50);
    4. imshow(bw)
    复制代码
    ipexrice_05.png
    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.
    1. cc = bwconncomp(bw, 4)
    2. cc =

    3.     Connectivity: 4
    4.        ImageSize: [256 256]
    5.       NumObjects: 95
    6.     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.
    1. grain = false(size(bw));
    2. grain(cc.PixelIdxList{50}) = true;
    3. imshow(grain);
    复制代码
    ipexrice_06.png
    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.
    1. labeled = labelmatrix(cc);
    2. 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.
    1. RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
    2. imshow(RGB_label)
    ipexrice_07.png

    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.
    1. 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.
    1. graindata(50).Area
    复制代码
    ans =

       194

    Step 10: Compute Area-based Statistics

    Create a new vector allgrains, which holds the area measurement for each grain.
    1. grain_areas = [graindata.Area];
    复制代码
    Find the grain with the smallest area.
    1. [min_area, idx] = min(grain_areas)
    2. grain = false(size(bw));
    3. grain(cc.PixelIdxList{idx}) = true;
    4. imshow(grain);
    复制代码
    min_area =

        61


    idx =

        16

    ipexrice_08.png

    Step 11: Create Histogram of the Area
    1. nbins = 20;
    2. figure, hist(grain_areas,nbins)
    3. title('Histogram of Rice Grain Area');
    复制代码
    ipexrice_09.png
    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信

    3503

    主题

    538

    听众

    5990

    积分

  • TA的每日心情
    开心
    2017-2-7 15:12
  • 签到天数: 691 天

    [LV.9]以坛为家II

    社区QQ达人 元老勋章 发帖功臣 新人进步奖 优秀斑竹奖 金点子奖 原创写作奖 最具活力勋章 助人为乐奖 风雨历程奖

    群组2013年国赛赛前培训

    群组2014年地区赛数学建模

    群组数学中国第二期SAS培训

    群组物联网工程师考试

    群组2013年美赛优秀论文解

    回复

    使用道具 举报

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

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-5-9 05:23 , Processed in 0.459086 second(s), 62 queries .

    回顶部