필터 지우기
필터 지우기

Detect a sinusoid in an image

조회 수: 9 (최근 30일)
HASNAIN
HASNAIN 2012년 6월 1일
편집: Image Analyst 2022년 5월 27일
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?

채택된 답변

Image Analyst
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);
  댓글 수: 11
Stephen john
Stephen john 2022년 5월 27일
@Image Analyst Where is the image file?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
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
HASNAIN
HASNAIN 2012년 6월 1일
Thank u very much for a speedy reply its just i didnt get an email to find out that you had replied!
A few minor things :
1)
binaryImage = redChannel < 128;
How did you know to choose the number 128?
2)
% Then find row # for each column
for col = 1 : size(redChannel, 2)
xy(col, 1) = col; % x value
xy(col, 2) = find(binaryImage(:, col), '1', 'first'); % y value
end
I dont quite understand what this for loop is doing here. When i run it i get : Subscripted assignment dimension mismatch error. Am i doing something wrong here?
Thanks!!
Image Analyst
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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by