Detect a sinusoid in an image
조회 수: 9 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2012년 6월 1일
편집: Image Analyst
2022년 5월 27일
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);
추가 답변 (1개)
Image Analyst
2012년 6월 1일
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
Image Analyst
2012년 6월 1일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!