[x,y]=imwtoxy(signal,V,T,px) |
---|
function [x,y]=imwtoxy(signal,V,T,px) %This function can be used to convert an image of a wave captured %from an oscilloscope to its x-y representation Which may be used to find %the mathematical properties of the wave by matlab functions. %-------------------------------------------------------------------------- % Simples code of the function: % Signal = image names with its kind .... example 'wave.jpg' % V = Volt per div in the oscilloscope panel % T = second per div in the oscilloscope panel % px = Number of pixel per centimeters in the oscilloscope grid image % x = Time vector of the result AC voltage wave % y = Alternating amplitude vector of the result AC voltage wave %-------------------------------------------------------------------------- % step 1: Read wave image and convert it to sharp bright one xim=imread(signal); x1=xim(:,:,1); x2=im2bw(x1); x3=bwmorph(x2,'skel',inf); %-------------------------------------------------------------------------- % step 2: Find the coordinates of the two edges of the wave image in its % matrix representation (pixel representation) n=size(x1); m=1; for j=1:1:n(2) c=0; for i=1:1:n(1) if x3(i,j)==1 c=c+1; k=i; end end if c~=0 y1(m)=c-k; y2(m)=-k; x(m)=j; m=m+1; end end y1=y1-min(y1); y2=y2-min(y2); x=x-min(x); %-------------------------------------------------------------------------- %step 3 :Convert waves axis scale from pixel to centimeters and split %y1 and y2 into positive and negative part y1=y1/px; y2=y2/px; y1=y1-max(y1)/2; y2=y2-max(y2)/2; x=x/px; %-------------------------------------------------------------------------- %step 4 :Convert waves axis scale from centimeters to volt and second y1=y1*V; y2=y2*V; x=x*T; %-------------------------------------------------------------------------- %step 5 :Find the middle point y between y1 and y2 dy=y1-y2; y=y1-dy/2; %-------------------------------------------------------------------------- %step 6 : Find smooth representation of y axis y=smooth(x,y,0.01,'rloess'); y=y'; %-------------------------------------------------------------------------- %step 7 : plotting the result wave with its image subplot 211;imshow(x1);xlabel('Sine wave captured from an oscilloscope') subplot 212;p=plot(x,y);grid on xlabel('Time (sec)'); ylabel('wave Amplitude(volt)'); set(p,'Color','red','LineWidth',2) end %-------------------------------------------------------------------------- %The function tested with sine wave image of size 5M pixel captured by %digital camera from analoge oscilloscope with %V=50/1000 volt/div and T=0.5/1000 second/div. %The size 5M pixel produce px=178 pixel/div. %A.Y.Iwyead , Sep 29, 2011 |
Convert a wave image to x-y function matlab
最新推荐文章于 2025-08-15 09:25:59 发布