TIF image intensity filter

4 views (last 30 days)
Robbie
Robbie on 30 Nov 2012
Hi,
I have a tif image, which is an object with high intensity light reflecting off of it and I want to locate the surface by using the pixels of maximum intensity. The file is loaded as follows:
% Read the *.tif image into the workspace and display it:
img = double(imread(tif_fileName));
img = ( img == max( img(:) ) );
% Check with a plot of maximum intensity:
imagesc(img); axis xy;
% Find the locations of pixels of max intensity:
[J I] = find(img);
The problem I have is that there is a line of pixels, where the surface is, which is quite obvious and I want to do a search for the ends of this line, but there are some erroneous pixels, elsewhere in the image, which are interfering with the search for these positions, does anyone have an idea of how to only do a search for a line of pixels, the closest I have got to doing this is something as follows:
for k = 1:( length(I) - 1 )
if ((( I(k + 1) ) - I(k) ) == 1) % This finds where the i +1th pixel minus the i pixel step is 1 (if more than one is noise (try plot of I and J)!
pixel_loc_I = k;
break
end
end
This finds the I location ok but the J location is problematic. Does anyone have an idea of how i could filter the data a bit or do something so that I only get the pixels I want clustered around the object reflection line? The line is a straight line, so I just need to locate the end points to define the surface I want.
Many Thanks,
Robbie
  6 Comments
Image Analyst
Image Analyst on 30 Nov 2012
A few months ago I did some code for an image that looked virtually identical. They had some kind of a bright edge or blade tilted in the middle of the picture and it was surrounded by a glow or glare of noise - pretty similar in appearance to your image. I think it either had material streaming around it, or it was illuminated by a laser, or some other reason why the noise was there. I can't find the message though. Maybe I'll take a shot at yours if I get time today.
Robbie
Robbie on 30 Nov 2012
In this case it is a laser illumination - any comments or ideas would be appreciated.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 Nov 2012
Edited: Image Analyst on 30 Nov 2012
Looks like a perfect situation to apply RANSAC: http://en.wikipedia.org/wiki/Ransac
You might try this (uses polyfit instead of ransac):
clc;
close all;
workspace;
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = 'C:\Users\Robbie\Documents\Temporary';
baseFileName = 'robbie.png';
% 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
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
grayImage = rgbImage(:,:, 2);
% Display the original color image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Threshold the image
binaryImage = grayImage > 240;
% Get rid of small blobs.
binaryImage = bwareaopen(binaryImage, 16);
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
title('Cleaned Binary Image', 'FontSize', fontSize);
% fit a line though the data
[y x] = find(binaryImage);
coeffs = polyfit(x, y, 1)
leftColumn = min(x)
rightColumn = max(x)
estimatedY = polyval(coeffs, [leftColumn, rightColumn])
% Plot a line along it.
subplot(2, 2, 4);
imshow(grayImage, []);
axis on;
hold on;
line([leftColumn, rightColumn], [estimatedY(1), estimatedY(2)],...
'Color', 'r', 'LineWidth', 3);
title('Original Image with Line Overlaid', 'FontSize', fontSize);
  1 Comment
Robbie
Robbie on 30 Nov 2012
Thanks for your help Image Analyst, I have managed to get something working and i like the ransac method, so I think I will probably try and implement that too. Your help is much appreciated.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!