Main Content

Segment Thermographic Image After Edge-Preserving Filtering

This example shows how to work with thermal images, demonstrating a simple segmentation. Thermal images are obtained from thermographic cameras, which detect radiation in the infrared range of the electromagnetic spectrum. Thermographic images capture infrared radiation emitted by all objects above absolute zero.

Read a thermal image into the workspace and usewhosto understand more about the image data.

I = imread("hotcoffee.tif"); whosI
Name Size Bytes Class Attributes I 240x320 307200 single

Compute the dynamic range occupied by the data to see the range of temperatures occupied by the image. The pixel values in this image correspond to actual temperatures on the Celsius scale.

range = [min(I(:)) max(I(:))]
range =1x2 single row vector22.4729 77.3727

Display the thermal image. Because the thermal image is a single-precision image with a dynamic range outside 0 to 1, you must use theimshow自动伸缩功能来显示图像。

figure imshow(I,[]) colormap(gca,hot) title("Original image")

Figure contains an axes object. The axes object with title Original image contains an object of type image.

Apply edge-preserving smoothing to the image to remove noise while still retaining image details. This is a preprocessing step before segmentation. Use theimguidedfilterfunction to perform smoothing under self-guidance. TheDegreeOfSmoothingname-value argument controls the amount of smoothing and is dependent on the range of the image. Adjust theDegreeOfSmoothingto accommodate the range of the thermographic image. Display the filtered image.

smoothValue = 0.01*diff(range).^2; J = imguidedfilter(I,"DegreeOfSmoothing",smoothValue); figure imshow(J,[]) colormap(gca,hot) title("Guided filtered image")

Figure contains an axes object. The axes object with title Guided filtered image contains an object of type image.

Determine threshold values to use in segmentation. The image has 3 distinct regions - the person, the hot object and the background - that appear well separated in intensity (temperature). Usemultithreshto compute a 2-level threshold for the image. This partitions the image into 3 regions using Otsu's method.

thresh = multithresh(J,2)
thresh =1x2 single row vector27.0018 47.8220

Threshold the image using the values returned bymultithresh. The threshold values are at 27 and 48 Celsius. The first threshold separates the background intensity from the person and the second threshold separates the person from the hot object. Segment the image and fill holes.

L = imquantize(J,thresh); L = imfill(L); figure imshow(label2rgb(L)) title("Label matrix from 3-level Otsu")

Figure contains an axes object. The axes object with title Label matrix from 3-level Otsu contains an object of type image.

画一个边界框的前景区域in the image and put the mean temperature value of the region in the box. The example assumes that the largest region is the background. Use theregionpropsfunction to get information about the regions in the segmented image.

props = regionprops(L,I,["Area","BoundingBox","MeanIntensity","Centroid"]);% Find the index of the background region.[~,idx] = max([props.Area]); figure imshow(I,[]) colormap(gca,hot) title("Segmented regions with mean temperature")forn = 1:numel(props)% If the region is not backgroundifn ~= idx% Draw bounding box around regionrectangle("Position",props(n).BoundingBox,"EdgeColor","c")% Draw text displaying mean temperature in CelsiusT = num2str(props(n).MeanIntensity,3)+" \circ C"; text(props(n).Centroid(1),props(n).Centroid(2),T,..."Color","c","FontSize",12)endend

Figure contains an axes object. The axes object with title Segmented regions with mean temperature contains 5 objects of type image, rectangle, text.

See Also

|||

Related Topics