Line profile through auto selected columns in an image

1 view (last 30 days)
I have an image of a regular pattern where I have roughly the locations of each object (by roughly I mean to within 1 pixel in x&y)
I want to be able to sum the line profiles of the columns. I originally summed all columns but it led to a "ringing effect" as some column were out of phase. I have now decided I want to perform the line scan only thru the columns that "are in phase" i.e. as indicated by the yellow lines.
I have the locations xi,yi of each of the red spots, for the example they are:
[xi,yi]=
2 9
2 19
5 4
5 14
8 9
8 19
11 3
11 14
13 9
13 19
In reality, there are hundreds of objects and the horizontal location of the spots maybe +-1 pixel out so infact my linescan needs to be of some thickness for each yellow line, and then suming all of these together.
Whats driving this is the need to give a measurement of fwhm to the illuminated pattern below, but due to the pattern i need to only include columns in phase.
I've no idea how to approach this.

Accepted Answer

Image Analyst
Image Analyst on 27 Jan 2016
I'd get rid of the out of phase spots then align and sum.
Sum the image horizontally to find the rows.
verticalProfile = sum(grayImage, 2);
Now threshold that to find rows
inRows = verticalProfile > someNumber;
and delete every other row by masking it out (setting those rows to 0).
[labeledRows, numRows] = bwlabel(inRows); % Each segment gets an ID number.
% Take every other one.
labeledRows = ismember(labeledRows, 1:2:numRows); % Extract every other row.
rowsToMask = labeledRows > 0; % Convert to a logical index.
grayImage(rowsToMask, :) = 0; % Mask every other row of spots.
Now you should have a rectangular, not hexagonal/diamond grid. If the grid is not aligned with the axes, find the location of the spots in the top and bottom row, compute the steepest slope between them, take the average of those slopes, and use that angle in imrotate() to rotate it so that it is aligned.
maskedImage = imrotate(maskedImage, angle);
Now do the sum vertically.
horizontalProfile = sum(maskedImage, 1);
The above is just off the top of my head (untested) so you'll have to tweak it. Obviously, start with the gray scale image, not the pseudocolored one.
  3 Comments
Jason
Jason on 27 Jan 2016
DilatedImage = imdilate(ROI, true(3));
%Create Gaussian Filter so to blur this dilated image
G = fspecial('gaussian', [5 5], 2);
blurredImage = imfilter(DilatedImage,G,'same'); % Blur Image
subplot(2,3,2)
imshow(blurredImage,[])
bim=ROI-blurredImage;
min(bim(:))
bim=bim+min(bim(:)); %make sure no negative values
I have tried this way to remove the background but: 1: my background subtracted image still has negative values 2: I have nasty edge effect that will mess up the verticalProfile
Image Analyst
Image Analyst on 27 Jan 2016
No, don't blur the image. Blur the profile - just fit the whole profile curve to a quadratic with polyfit, then subtract that curve from your sloping oscillating curve to get a flattened one. See attached polyfit demo.
coefficients = polyfit(1:rows, verticalProfile, 2);
fittedY = polyval(coefficients, 1:rows);
flatSignal = verticalProfile - fittedY;
or something pretty much like that. Then threshold
inROws = flatSignal > 5000; % or whatever

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!