How to determine the period of a pattern contained in a grayscale image?

3 views (last 30 days)
Hello,
I want to determine the period of a specific pattern in a grayscale image. The matrix representing the image is a 86x60000 matrix containing values between 0-255 (grayscale). I read about different approaches using functions like findpeaks, ischange and crosscorrelation to determine the period but I am not quite sure how I could use them in order to solve my problem. I am new to matlab and therefore I am not familiar with all functionalities matlab provides. Do you have any ideas how to tackle this problem?
Here is a picture that illustrates what I want to calculate.

Accepted Answer

Image Analyst
Image Analyst on 4 Jun 2022
Not too hard. Just threshold then scan to find the top edge. Then invert and call findpeaks. Here's a start
grayImage = imread(fileName);
if ndims(grayImage) > 1
grayImage = rb2gray(grayImage);
end
mask = grayImage > someThresholdValue;
[rows, columns] = size(grayImage);
topRows = rows * ones(1, columns);
for col = 1 : columns
tr = find(mask(:, col), 1, 'first');
if ~isempty(tr)
topRows(col) = tr;
end
end
% Invert
topRows = rows - topRows;
% Find peaks
[peakValues, columnsOfPeaks] = findpeaks(topRows, 'MinPeakDistance', columns/10);
peakValues = rows - peakValues;
% Plot on image.
hold on;
x = 1 : columns;
plot(x(columnsOfPeaks), peakValues, 'rv', 'MarkerSize', 15, 'LineWidth', 2);
Attach your actual image if you can't figure it out.
  2 Comments
Glypton
Glypton on 4 Jun 2022
Edited: Glypton on 4 Jun 2022
Thank you for your response!
I am new to image processing. There is no image per se. Just a big matrix with values between 0-255 or 150-255 since there are no black pixels contained in the matrix. The actual dimension of the matrix is 86x6*10^5. I extracted the first 6*10^4 columns to show you what I want to achieve. This means that the above pattern is repeated 10 times with some noises. Now I try to calculate the period of that pattern. So, there is no image but a big matrix. Sorry for being unclear and thank you again for your response!
Image Analyst
Image Analyst on 4 Jun 2022
It doesn't matter what you call it: image or matrix. Essentially they're the same. If you need any more help, ask. And attach the matrix in a .mat file with the paperclip icon.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!