% 检测多焊和连焊 seq=strel('diamond',5); Img_bw=imclose(Img_bw,seq);%闭操作 [y,x]=find(Img_bw==1); k = convhull(x,y); Area_hanjie=length(x); %连通区域面积 area_tubao = polyarea(x,y); % 连通区域凸包面积 Edge_1=edge(Img_bw,'canny'); % figure;imshow(Edge_1); zhouchang=length(find(Edge_1==1)); % 连通区域周长 if zhouchang/Area_hanjie<0.07 %根据周长/面积的比作为特征将焊接块取出来 if Area_hanjie>20000 % 常规焊接块与多焊连焊的面积不同 if area_tubao/Area_hanjie>0.16 % 多焊多凹区域,根据该特征实现多焊与连焊的区分 text(col_left, row_up-30, '连焊','FontSize',16); hold on; line(rect(:,1),rect(:,2),'color','g','LineWidth',2); else text(col_left, row_up-30, '多锡','FontSize',16); hold on; line(rect(:,1),rect(:,2),'color','b','LineWidth',2); end end end
时间: 2023-06-26 08:03:10 浏览: 36
这段代码主要是用来检测焊接区域中的多焊和连焊问题。首先使用了闭操作来减少图像中的噪点,然后使用convhull函数计算连通区域的凸包面积和面积,并计算出焊接区域的周长。根据周长/面积的比作为特征将焊接块取出来,如果该区域面积大于20000且凸包面积/面积大于0.16,则表示该区域为多焊或连焊区域。最后,在图像中标注出检测结果。
相关问题
if max(aa)>1 text(round(w/2), round(h/2), '气孔','FontSize',8,'BackgroundColor', [1 1 1]); else text(round(w/2), round(h/2), '裂纹','FontSize',8,'BackgroundColor', [1 1 1]); end Img_edge=edge(Img_gray,'canny',0.3); seq=strel('rectangle',[15,15]); Img_bw=imclose(Img_edge,seq);
这段代码使用了MATLAB的图像处理工具箱,首先判断图像中是否存在大于1的最大值,如果存在则在图像中心位置显示“气孔”,否则显示“裂纹”。接下来使用Canny边缘检测算法处理灰度图像,然后使用矩形结构元素进行闭运算操作,得到二值化图像Img_bw。其中,strel函数用于构造结构元素,rectangle参数表示矩形的尺寸为15x15。
id_seq = 100 seq = np.copy(sequence_target_drop_test[id_seq]) seq[seq == mask_value] = np.nan seq = scaler_target.inverse_transform(seq)
These lines of code are used to extract a sequence of values from the `sequence_target_drop_test` array with an index of `id_seq`. The `np.copy` function is used to make a copy of the sequence so that the original array is not modified. The value `mask_value` is replaced with `np.nan` to indicate missing values. Then, the `scaler_target` object is used to invert the scaling performed on the sequence during preprocessing. The resulting sequence is a set of actual values that can be compared to predicted values to evaluate the performance of a model.