Infrared images threshold
Ältere Kommentare anzeigen
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.
Antworten (4)
Walter Roberson
am 14 Nov. 2011
0 Stimmen
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 Kommentare
Syahrul Niezam
am 27 Jan. 2012
Walter Roberson
am 27 Jan. 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
am 27 Jan. 2012
Walter Roberson
am 28 Jan. 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)"
Image Analyst
am 14 Nov. 2011
0 Stimmen
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 Kommentare
Syahrul Niezam
am 27 Jan. 2012
Walter Roberson
am 27 Jan. 2012
Yes it does.
Syahrul Niezam
am 27 Jan. 2012
Image Analyst
am 28 Jan. 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
am 28 Jan. 2012
Walter Roberson
am 28 Jan. 2012
Please show your code and please show the error message text and show which line the error occurs on.
Syahrul Niezam
am 28 Jan. 2012
Image Analyst
am 28 Jan. 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.
Image Analyst
am 28 Jan. 2012
% 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 Kommentare
Syahrul Niezam
am 28 Jan. 2012
Mohsen
am 11 Jul. 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
am 11 Jul. 2022
@Mohsen, use the attached function instead.
Mohsen
am 12 Jul. 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
am 12 Jul. 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:
riadi marta dinata adi
am 19 Sep. 2015
0 Stimmen
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 Kommentar
Walter Roberson
am 19 Sep. 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.
Kategorien
Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!