Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Differentiation can be used to see where the colour changes from black to white or vice versa.
- % Example code for collecting the data and getting rid of noise
- clc;
- clear all;
- close all;
- MyRawImage = double(imread('letter_A_noisy.jpg'));
- OneLineData = MyRawImage(850,1:end)
- plot(OneLineData);
- ws = 6;
- % OneLineDataAve(1) = (OneLineDataAve(1)+OneLineDataAve(2)+OneLineDataAve(3)+OneLineDataAve(4))/4;
- % OneLineDataAve(2) = (OneLineDataAve(2)+OneLineDataAve(3)+OneLineDataAve(4)+OneLineDataAve(5))/4;
- for i=1:length(OneLineData)-(ws-1)
- % OneLineDataAve(i) = (OneLineData(i)+OneLineData(i+1)+OneLineData(i+2))/3;
- OneLineDataAve(i) = sum(OneLineData(i:i+(ws-1)))/ws;
- end;
- hold OneLineDataplot(OneLineDataAve)
- % DataAveDif(1) = OneLineDataAve(2) - OneLineDataAve(1);
- % DataAveDif(2) = OneLineDataAve(3) - OneLineDataAve(2);
- %% This for loop is made obsolete by the line of code beneath it %%
- % for i=1:length(OneLineDataAve)-1
- % DataAveDif(i) = OneLineDataAve(i+1) - OneLineDataAve(i);
- % end;
- DataAveDif = abs(OneLineDataAve(2:length(OneLineDataAve)) - OneLineDataAve(1:length(OneLineDataAve)-1)) % abs() converts to absolute value
- % The purpose of the above line is to take the differential of the average to see where the data changes from high to low.
- figure;
- plot(DataAveDif);
- xlim([850 1500]);
- [pks,locs] = findpeaks(DataAveDif,'MinPeakHeight',25,'MinPeakDistance',6); % findpeak is a MATLAB function, which means it has options
- % MinPeakHeight lets you only look at peaks above a certain height
- % MinPeakDistance allows you to only take the highest peak in a specified domain
- figure;
- plot(DataAveDif);
- hold on;
- plot(locs,pks,'or'); % Plots a red o at every peak
- xlim([850 1500]);
- widths = locs(2:end) - locs(1:end-1)
- % The locs variable are the peaks, using that you can calculate the widths using the above line of code
- % 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...
- % Then you must round the values to get the barcode ratio lengths (3, 1, 1, 3, etc...);
- widths = round(widths/min(widths))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement