• 大小: 61.72MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2022-08-20
  • 语言: 其他
  • 标签: image_defect  

资源简介

工业上太阳能电池板的缺陷检测识别,主要针对裂纹,斑点进行检测。详细内容参加博客:https://blog.csdn.net/cuixing001/article/details/83246218

资源截图

代码片段和文件信息

%% 用于太阳能电池板缺陷检测,缺陷用红色标记,正常就不标记
% author:cuixingxing
% email:cuixingxing150@gmail.com
%
patch_rows = 6;
patch_cols = 10;
imds = imageDatastore(‘./defect_image_cell‘... % 改成自己.jpg图像所在目录即可
    ‘includeSubfolders‘true...
    ‘fileExtensions‘{‘.jpg‘});
nums = length(imds.Files);


%% main loop
for k = 1:nums
    img1 = imresize(readimage(imdsk)0.3);
    if size(img13)==3
        img1 = rgb2gray(img1);
    end
    
    %% get max rect
    bw = imbinarize(img10.35);
    se = strel(‘disk‘3);
    bw_close = imclose(bwse);
    s = regionprops(bw_close‘BoundingBox‘);
    max_area = 0;
    max_rect = [];
    for i = 1:length(s)
        area = s(i).BoundingBox(3)*s(i).BoundingBox(4);
        if area>=max_area
            max_area = area;
            max_rect = s(i).BoundingBox;
        end
    end
    
    %% get all patches rects
    x = linspace(max_rect(1)max_rect(1)+max_rect(3)11);
    y = linspace(max_rect(2)max_rect(2)+max_rect(4)7);
    [XY] = meshgrid(xy);
    square_rects = zeros(patch_rows*patch_cols4);
    for i = 1:patch_rows
        for j = 1:patch_cols
            square_rects(patch_cols*(i-1)+j:) = [X(ij)Y(ij)X(ij+1)-X(ij)Y(i+1j)-Y(ij)];
            current_rect = square_rects(patch_cols*(i-1)+j:);
        end
    end
    
    %% detect each patch defect
    img1_RGB = cat(3img1img1img1);
    for i = 1:patch_rows*patch_cols
        x = floor(square_rects(i1));
        y = floor(square_rects(i2));
        width = floor(square_rects(i3));
        height = floor(square_rects(i4));
        current_patch = img1(y:(y+height)x:(x+width));
        [bw_edthreshOut] = edge(current_patch‘prewitt‘0.040);
        SE = strel(‘disk‘36);
        dilate_img = imdilate(bw_edSE);
        [bwthreshold] = edge(current_patch‘canny‘[0.05850.2563]);
        border = round(0.12*size(bw1));
        bw_mask = false(size(bw));
        bw_mask(border:size(bw1)-borderborder:size(bw2)-border) = true;
        mask = bw_mask&bw;
        mask = mask&(~dilate_img);
        R = current_patch;G = current_patch;B = current_patch;
        R(mask) = 255;G(mask) = 0;B(mask) = 0;
        draw_patch = cat(3RGB);
        img1_RGB(y:(y+size(draw_patch1)-1)x:(x+size(draw_patch2)-1):) = draw_patch;
    end
    [pathname~] = fileparts(imds.Files{k});
    save_name = fullfile(path[name‘_draw.png‘]);
    imwrite(img1_RGBsave_name);
%     imshowpair(img1img1_RGB‘montage‘)
end


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-21 21:35  image_quexian\
     目录           0  2018-10-21 19:52  image_quexian\defect_image_cell\
     文件     2363921  2018-01-01 21:51  image_quexian\defect_image_cell\1.jpg
     文件     2361734  2018-01-09 15:42  image_quexian\defect_image_cell\10.jpg
     文件      889425  2018-10-21 20:49  image_quexian\defect_image_cell\10_draw.png
     文件     2430542  2018-01-09 15:52  image_quexian\defect_image_cell\11.jpg
     文件      911539  2018-10-21 20:49  image_quexian\defect_image_cell\11_draw.png
     文件     2402243  2018-01-09 15:55  image_quexian\defect_image_cell\12.jpg
     文件      901133  2018-10-21 20:49  image_quexian\defect_image_cell\12_draw.png
     文件     2453385  2018-01-09 15:58  image_quexian\defect_image_cell\13.jpg
     文件      918964  2018-10-21 20:49  image_quexian\defect_image_cell\13_draw.png
     文件     2431960  2018-01-09 16:03  image_quexian\defect_image_cell\14.jpg
     文件      909149  2018-10-21 20:49  image_quexian\defect_image_cell\14_draw.png
     文件     2429316  2018-01-09 16:05  image_quexian\defect_image_cell\15.jpg
     文件      908951  2018-10-21 20:49  image_quexian\defect_image_cell\15_draw.png
     文件     2391343  2018-01-09 16:07  image_quexian\defect_image_cell\16.jpg
     文件      897362  2018-10-21 20:49  image_quexian\defect_image_cell\16_draw.png
     文件     2396920  2018-01-09 16:10  image_quexian\defect_image_cell\17.jpg
     文件      899967  2018-10-21 20:49  image_quexian\defect_image_cell\17_draw.png
     文件     2354027  2018-01-09 16:16  image_quexian\defect_image_cell\18.jpg
     文件      889075  2018-10-21 20:49  image_quexian\defect_image_cell\18_draw.png
     文件     2431096  2018-01-09 16:18  image_quexian\defect_image_cell\19.jpg
     文件      910978  2018-10-21 20:49  image_quexian\defect_image_cell\19_draw.png
     文件      890094  2018-10-21 20:49  image_quexian\defect_image_cell\1_draw.png
     文件     2423296  2018-01-01 23:27  image_quexian\defect_image_cell\2.jpg
     文件     2393961  2018-01-09 16:20  image_quexian\defect_image_cell\20.jpg
     文件      902420  2018-10-21 20:49  image_quexian\defect_image_cell\20_draw.png
     文件      911488  2018-10-21 20:49  image_quexian\defect_image_cell\2_draw.png
     文件     2374665  2018-01-02 09:23  image_quexian\defect_image_cell\3.jpg
     文件      893414  2018-10-21 20:49  image_quexian\defect_image_cell\3_draw.png
     文件     2338070  2018-01-09 10:34  image_quexian\defect_image_cell\4.jpg
............此处省略12个文件信息

评论

共有 条评论

相关资源