Infrared images threshold

Hello. I'm doing assignment project using infrared images. I would like to segment the images into certain regions using threshold method. I tried searching in the internet, and found the Otsu's method. I'm not sure it can be applied in infrared images or not. Is there other methods beside that?
Thank you.

Respuestas (4)

Walter Roberson
Walter Roberson el 14 de Nov. de 2011

0 votos

Yes, Otsu's method is valid for infrared images; you can use the graythresh routine if you have access to that toolbox.
However, as is the case with all automatic thresholding routines, the routines are not sensitive to context, and have no idea what is "important" to the problem at hand. With infrared, sometimes you are interested in the warm spots and sometimes you are interested in the cold spots, and sometimes you are interested in spots that are "warmish" but cooler than their surroundings (e.g., detecting an living (warmish) obstruction against a hot building against a cold sky). A routine such as Otsu's is not going to know what is important.

4 comentarios

Syahrul Niezam
Syahrul Niezam el 27 de En. de 2012
sorry for late reply. that's true, it's not suitable to use automatic thresholding such as otsu etc. i tried using given codes from other authors such as:
c = imread('image1_069.jpg');
b = unit8(a<90);
b(a >= 110) = 180;
b(a >= 150) = 200;
b(a >= 200) = 255;
is it correct? the output is set to 180 if the input grayscale is between 90~110 and so forth. correct me if wrong.
Thanks in advance.
Walter Roberson
Walter Roberson el 27 de En. de 2012
You read the image in to "c" but you tests the values of "a".
The code you show is not thresholding: it is quantization.
Syahrul Niezam
Syahrul Niezam el 27 de En. de 2012
I'm sorry. this is the correct one; my codes for segmentation image into four regions by threshold values.
a = imread('image1_069.jpg');
b = unit8(a<90);% In this order!
b(a >= 110) = 180;
b(a >= 150) = 200;
b(a >= 200) = 255;
btw, what is quantization.
Walter Roberson
Walter Roberson el 28 de En. de 2012
unit8() is not defined. You probably mean uint8()
http://en.wikipedia.org/wiki/Quantization
"Quantization is the procedure of constraining something from a relatively large or continuous set of values (such as the real numbers) to a relatively small discrete set (such as the integers)"

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 14 de Nov. de 2011

0 votos

What Walter says is true. Often I encounter histograms that are like skewed Gaussians, instead of a nice well separated pair of Gaussians like you'd want to represent foreground and background. In cases like that (which are frequent with me) I prefer the triangle method: http://www.mathworks.com/matlabcentral/fileexchange/28047-gray-image-thresholding-using-the-triangle-method It seems to pick a better threshold than Otsu where you have more of a blending of foreground and background pixels rather than a nice bimodal histogram. Often you get some first shot at your objects via thresholding and then you have to further narrow down objects to valid foreground objects via things like filtering them based on their shape or area, etc. So often detecting foreground by simply thresholding is not enough - you need more than that.

8 comentarios

Syahrul Niezam
Syahrul Niezam el 27 de En. de 2012
I'm sorry for late reply.
Does the triangle method work on grayscale infrared images?
Thanks in advance.
Walter Roberson
Walter Roberson el 27 de En. de 2012
Yes it does.
Syahrul Niezam
Syahrul Niezam el 27 de En. de 2012
I read through the codes and demo of triangle method, it is mentioned that the codes are for rgb image, not grayscale image.
Image Analyst
Image Analyst el 28 de En. de 2012
Did you read the same file we did? The demo file where it says
%The demo reads a RGB image of vegetation against soil background.
%This image is converted to a gray level image
and the actual function where it says this:
% Use Triangle approach to compute threshold (level) based on a
% 1D histogram (lehisto). num_bins levels gray image.
% INPUTS
% lehisto : histogram of the gray level image
% num_bins: number of bins (e.g. gray levels)
% OUTPUT
% level : threshold value in the range [0 1];
Where on earth do you see that it says it's not for grayscale images? I didn't see that stated anywhere in the code. Tell me which file at which line number it says that.
Syahrul Niezam
Syahrul Niezam el 28 de En. de 2012
sorry for my mistake.i just curious about the error in lehisto when execute the given codes.
Walter Roberson
Walter Roberson el 28 de En. de 2012
Please show your code and please show the error message text and show which line the error occurs on.
Syahrul Niezam
Syahrul Niezam el 28 de En. de 2012
I had tried executing the triangle_th codes in given link with this image;
http://i42.tinypic.com/bdplk1.jpg
and then this error appeared on command window:
??? Input argument "lehisto" is undefined.
Error in ==> th2 at 30
[h,xmax]=max(lehisto);
I had also executed the Demo_triangle_th codes and this error appeared on command window:
??? Undefined function or method 'triangle_th' for input arguments of type 'double'.
Error in ==> th at 11
[level]=triangle_th(lehisto,256);
I don't know what lehisto means. Is it related with the image used?
Thank you a lot in advance.
Image Analyst
Image Analyst el 28 de En. de 2012
Come on, did you actually pass lehisto into the function? No, you didn't. I guess you could benefit from a demo where I explicitly do it for you. See my other answer.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 28 de En. de 2012

0 votos

% Demo to do triangle thresholding of an image.
% By ImageAnalyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Syahrul\Documents\Temporary';
baseFileName = 'bdplk1.jpg';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
axis on;
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
[level]=triangle_th(pixelCount, 256)
thresholdvalue = int32(level * intmax(class(grayImage)));
binaryImage = grayImage > level * 255;
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
caption = sprintf('Binarized at %d', thresholdvalue);
title(caption, 'FontSize', fontSize);

5 comentarios

Syahrul Niezam
Syahrul Niezam el 28 de En. de 2012
Thanks for your concern. I appreciate all your opinion and ideas. :)
I'll try my best.
Mohsen
Mohsen el 11 de Jul. de 2022
Hello , when I start the plan I got this error :
"Undefined function or variable 'triangle_th'.
Error in process (line 46)
[level] = triangle_th(pixelCount, 256); "
what should I do?
Image Analyst
Image Analyst el 11 de Jul. de 2022
@Mohsen, use the attached function instead.
Mohsen
Mohsen el 12 de Jul. de 2022
thank you , I past it.
but another error happens :
""" Error using images.internal.imageDisplayValidateParams>validateCData (line 119)
If input is logical (binary), it must be two-dimensional.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 245)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in process (line 52)
imshow(binaryImage, []); """
Image Analyst
Image Analyst el 12 de Jul. de 2022
Like it says, there is some problem with binaryImage. It's not a regular gray scale, color, indexed, or binary image. What is it?
whos binaryImage
If you have more trouble, start a whole new discussion thread and attach your image and code after reading this:

Iniciar sesión para comentar.

riadi marta dinata adi
riadi marta dinata adi el 19 de Sept. de 2015

0 votos

which i know..... matlab cant' read IR on image,this link my be describe how about this... http://www.researchgate.net/post/How_do_you_convert_a_RGB_image_to_an_IR_image_Is_it_possible_using_MATLAB

1 comentario

Walter Roberson
Walter Roberson el 19 de Sept. de 2015
That link says nothing about MATLAB being unable to read IR images. The link is saying that if what you have is an RGB image then you cannot convert it to an IR image.
Someone posted a link the other day to an interesting article pointing out that certain Canon cameras can have (weak) IR extracted from their RAW images.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Nov. de 2011

Comentada:

el 12 de Jul. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by