Detect a sinusoid in an image
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
HASNAIN
am 1 Jun. 2012
Bearbeitet: Image Analyst
am 27 Mai 2022
Hi all,
I am fairly new to image processing in MATLAB and I'm trying to learn as much as possible. So my aim is to extract a sinusoid that is drawn on graph paper which has been scanned in as an image. As i said, I am fairly new to image processing and trying very hard to learn as much as possible.
So the image has a sinusoid which is time varying and the background is that of a graph paper.
Could anyone point me in the right direction to go about accomplishing this task please?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 1 Jun. 2012
Bearbeitet: Image Analyst
am 27 Mai 2022
Try this code:
clc;
clearvars;
close all;
workspace;
fontSize = 20;
ullFileName = 'C:\Users\Hasnain\Documents\Temporary\single_sine_wave.png';
indexedImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(indexedImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(indexedImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Find the sine wave. This is where the image = 93.
redChannel = indexedImage == 93;
subplot(2, 2, 2);
imshow(redChannel, []);
title('Sine Wave Image', 'FontSize', fontSize);
% Then find row # for each column
numberOfColumns = size(redChannel, 2);
x = zeros(numberOfColumns, 1);
y = zeros(numberOfColumns, 1);
for col = 1 : numberOfColumns
x(col, 1) = col; % x value
thisy = find(redChannel(:, col), 1, 'first'); % y value
if isempty(thisy)
y(col) = nan; % y value
else
y(col) = thisy; % y value
end
end
% Get rid of nan's
nanIndexes = isnan(y);
y(nanIndexes) = [];
x(nanIndexes) = [];
% Plot what we have so far.
subplot(2, 2, 3);
plot(x, y, 'b', 'LineWidth', 5);
grid on;
title('Sine Wave Image', 'FontSize', fontSize);
xlabel('Column', 'FontSize', fontSize);
ylabel('Row', 'FontSize', fontSize);
% Scale to calibrated units.
% Scale y
y_Range = max(y) - min(y);
scaled_y = 1 + 2 * (min(y) - y) / y_Range;
% Scale x
scaled_x = linspace(0, 65, length(scaled_y));
subplot(2, 2, 4);
plot(scaled_x, scaled_y, 'b', 'LineWidth', 5);
grid on;
title('Sine Wave Image in Calibrated Units', 'FontSize', fontSize);
xlabel('Sample Number', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
11 Kommentare
Image Analyst
am 27 Mai 2022
@Stephen john it was in a link in one of his other comments:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1013145/image.png)
Weitere Antworten (1)
Image Analyst
am 1 Jun. 2012
What do you mean by detect? How about this:
sinusiodPixels = grayImage < thresholdValue;
That will give you a binary image of anything dark on your paper. Or so you want the parameters like the wavelength and amplitude?
4 Kommentare
Image Analyst
am 1 Jun. 2012
I see you need some more help. So I downloaded your image and discovered it was an indexed image rather than an RGB image. So I made slight modifications to the code to get the blue sine wave, and added the parts on getting the x,y coordinates and transforming them into calibrated coordinates and plotting. See code in my other Answer here on this page.
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!