Advertisement
Guest User

matlab

a guest
Feb 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.08 KB | None | 0 0
  1. % Differentiation can be used to see where the colour changes from black to white or vice versa.
  2.  
  3. % Example code for collecting the data and getting rid of noise
  4.  
  5. clc;
  6. clear all;
  7. close all;
  8. MyRawImage = double(imread('letter_A_noisy.jpg'));
  9. OneLineData = MyRawImage(850,1:end)
  10. plot(OneLineData);
  11. ws = 6;
  12. % OneLineDataAve(1) = (OneLineDataAve(1)+OneLineDataAve(2)+OneLineDataAve(3)+OneLineDataAve(4))/4;
  13. % OneLineDataAve(2) = (OneLineDataAve(2)+OneLineDataAve(3)+OneLineDataAve(4)+OneLineDataAve(5))/4;
  14. for i=1:length(OneLineData)-(ws-1)
  15.     % OneLineDataAve(i) = (OneLineData(i)+OneLineData(i+1)+OneLineData(i+2))/3;
  16.     OneLineDataAve(i) = sum(OneLineData(i:i+(ws-1)))/ws;
  17. end;
  18. hold OneLineDataplot(OneLineDataAve)
  19.  
  20. % DataAveDif(1) = OneLineDataAve(2) - OneLineDataAve(1);
  21. % DataAveDif(2) = OneLineDataAve(3) - OneLineDataAve(2);
  22.  
  23. %% This for loop is made obsolete by the line of code beneath it %%
  24. % for i=1:length(OneLineDataAve)-1
  25. %   DataAveDif(i) = OneLineDataAve(i+1) - OneLineDataAve(i);
  26. % end;
  27. DataAveDif = abs(OneLineDataAve(2:length(OneLineDataAve)) - OneLineDataAve(1:length(OneLineDataAve)-1)) % abs() converts to absolute value
  28. % The purpose of the above line is to take the differential of the average to see where the data changes from high to low.
  29. figure;
  30. plot(DataAveDif);
  31. xlim([850 1500]);
  32.  
  33. [pks,locs] = findpeaks(DataAveDif,'MinPeakHeight',25,'MinPeakDistance',6); % findpeak is a MATLAB function, which means it has options
  34. % MinPeakHeight lets you only look at peaks above a certain height
  35. % MinPeakDistance allows you to only take the highest peak in a specified domain
  36. figure;
  37. plot(DataAveDif);
  38. hold on;
  39. plot(locs,pks,'or'); % Plots a red o at every peak
  40. xlim([850 1500]);
  41.  
  42. widths = locs(2:end) - locs(1:end-1)
  43. % The locs variable are the peaks, using that you can calculate the widths using the above line of code
  44. % If you locate the minimum width, and divide everything by it, you will have numbers along the line of 1.0, 1.3, 3.0, 3.5, etc...
  45. % Then you must round the values to get the barcode ratio lengths (3, 1, 1, 3, etc...);
  46. widths = round(widths/min(widths))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement