Ive been doing some reseach on localizing defect and actually to provide information about the real coordianate of the defect such as in x and y axis or meters. im detecting red colour, filter it and i segmentized it. But i couldnt find the algorithm to locate the actual location of the defect in the thermal image.
MATLAB: Localization defect real coordinate
Computer Vision Toolboximage processingImage Processing Toolboxspatial calibrationthermal
Related Solutions
Try this:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 13;% read the original image
rgbImage = imread('defects1.png');% Display the image.
subplot(2, 2, 1);imshow(rgbImage);axis('on', 'image');title('Original RGB Image', 'FontSize', fontSize);impixelinfo;% call createMask function to get the mask and the filtered image
[mask,maskedRGBImage] = createMask(rgbImage);% Display the image.subplot(2, 2, 2);imshow(mask);axis('on', 'image');impixelinfo;title('Mask', 'FontSize', fontSize);subplot(2, 2, 3);% Take 13 largest blobs.
mask = bwareafilt(mask, 13);imshow(mask);hold on;% Make measurements.
props = regionprops(mask, 'Centroid');xy = vertcat(props.Centroid);for k = 1 : size(xy, 1) x = xy(k, 1); y = xy(k, 2); caption = sprintf(' %d', k); plot(x, y, 'r+', 'MarkerSize', 20); text(x, y, caption, 'Color', 'r', 'FontWeight', 'bold', 'FontSize', 20);endg = gcf;g.WindowState = 'maximized';distances = pdist2(xy, xy)%distancesInPixels = pdist2(xy, xy);
%distancesInCm = distancesInPixels * cmPerPixel;
function [BW,maskedRGBImage] = createMask(RGB)%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 18-Feb-2021
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.049;channel1Max = 0.160;% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;channel2Max = 1.000;% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;channel3Max = 1.000;% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ... (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ... (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);BW = sliderBW;% Initialize output masked image based on input image.
maskedRGBImage = RGB;% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;end
Use the Color Thresholder app on the apps tab of the tool ribbon. I'd use hsv color space. Then adjust the thresholds and Export the code into a new function m-file.
rgbImage = imread('Captur11.jpg');subplot(2, 1, 1);imshow(rgbImage);[BW,maskedRGBImage] = createMask(rgbImage);% Fill holes
BW = imfill(BW, 'holes');% Take largest blob.
BW = bwareafilt(BW, 1);subplot(2, 1, 2);imshow(BW)function [BW,maskedRGBImage] = createMask(RGB)%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 11-May-2020
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.584;channel1Max = 0.619;% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.856;channel2Max = 1.000;% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;channel3Max = 1.000;% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ... (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ... (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);BW = sliderBW;% Initialize output masked image based on input image.
maskedRGBImage = RGB;% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;end
Best Answer