From: Lukáš Jiřiště Date: Mon, 19 Aug 2024 11:38:03 +0000 (+0200) Subject: Remove majority of Bubliny.m X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=6abed63484077e23a2564d7aa188ca0f122a8484;p=Bubble_column.git Remove majority of Bubliny.m This is a start of major rewrite, so much of the code is thrown out. The seed of the idea is implemented - maxfig, minfig and meanfig. Those three hold the maximum, minimum and mean value of each pixel during the whole measurement and should hold info about how to further process the data. --- diff --git a/Bubliny.m b/Bubliny.m index 3e103f9..0f8f3f5 100755 --- a/Bubliny.m +++ b/Bubliny.m @@ -1,12 +1,11 @@ - close all; % deletes all figures whose handles are not hidden clear all; % removes all variables from memory -clc; % clears the Command Window display %% vstupni data T:\00-Orvalho\Travnickova\Bubble column % %% + % User dialog for the data directory used for files DirectoryName = get_data_dir(); @@ -29,11 +28,13 @@ if isempty(SelectedDirectory) % ha end nSelectedDirectory = numel(SelectedDirectory); % Counts directories +%{ [ResFile, res_path] = uiputfile('*.xlsm', 'Save results to'); if (ResFile == 0) error('No file elected to save the results to.') end ResFile = [res_path, ResFile]; +%} % helper variables infmt = 'hh:mm:ss.SS'; % Time format in file names @@ -41,7 +42,7 @@ FileType = '*.png'; % extension of image file %% % load of all directories in cycles -for iii=1:1:nSelectedDirectory % Cycles for directories with files +for iii=1:nSelectedDirectory % Cycles for directories with files %% @@ -52,20 +53,6 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files nFFiles = numel(FFiles); % Counts files LevelNum=str2double(SelectedDirectory{iii}(7:9))*1000; -% Initiation from the first file - ImageName = FFiles(1).name; - start_time = duration([(ImageName(8:9)) ':' (ImageName(10:11)) ':' (ImageName(12:16))],'Format',infmt); - Figure = imread([FFiles(1).folder '/' ImageName]); - ContrastFigure = imadjust(Figure); % Adjust the contrast of the image using imadjust. - [MeterScale, polypar_Metr] = meter(SelectedDirectory{iii}, ContrastFigure, ResFile); - D_num=str2double(SelectedDirectory{iii}(21)); % position of camera - -% Set loop variables - step=1; - startFile= 40; %945; %200 (20. ) - endFile= 110; %nFFiles; %1000; %325 (20.) - nFFiles=(endFile - startFile / step) + 1; % Attention!!! - %% variable allocation Height = zeros(1,nFFiles); @@ -74,181 +61,53 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files Metr_fit_B = zeros(1,nFFiles); %% -% load all files in a loop - for jjj=1:nFFiles % Cycles for figures files - file_ind = startFile + (jjj - 1) * step; - ImageName = FFiles(file_ind).name; - Figure = imread([FFiles(file_ind).folder '/' ImageName]); - ContrastFigure = imadjust(Figure); % Adjust the contrast of the image using imadjust. - IntensitiesAverFin{jjj} = get_representative_intensities(ContrastFigure); - -% Figure with average intensity, without the bands with hole and meter - f = figure(); - ax = axes(f); - imshow(ContrastFigure, 'Parent', ax) - hold(ax, 'on'); - plot(ax, IntensitiesAverFin{jjj},'-y','linewidth',2) - if jjj > 1 %subtracts the intensities - plot(IntensitiesAverFin{jjj-step},'Color',[0.9290 0.6940 0.1250],'linewidth',2) - hold on - IntensitiesAverFin_2{jjj}=IntensitiesAverFin{jjj}-IntensitiesAverFin{jjj-step}; - waytrend=mean(IntensitiesAverFin_2{jjj},2); % waytrend will tell whether to calculate the minimum or maximum green intensity IntensitiesAverFin_2{jjj} - if waytrend<=0; - plot(-IntensitiesAverFin_2{jjj},'-g','linewidth',2) - else - plot(IntensitiesAverFin_2{jjj},'-g','linewidth',2) - end - hold on - end - - Time(jjj)=duration([(ImageName(8:9)) ':' (ImageName(10:11)) ':' (ImageName(12:16))],'Format',infmt) - start_time; - infmd = ['yy' 'MM' 'dd']; - Date(jjj) = datetime(ImageName(1:6),'InputFormat',infmd); - - % % plot(lk,abs(pk),'oc','linewidth',2) - if D_num==1 - LevelPixels=MeterScale(1+(1000-LevelNum)/100); % x level in pixels in the original image - if jjj == 1 - [pk,lk] = findpeaks(-IntensitiesAverFin{jjj}(1:(LevelPixels+30))); %10 - [Height(jjj),pkH]=max(pk); - qH=lk(pkH); - Metr_fit_H(jjj)=polyval(polypar_Metr,qH); - plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) - else - if waytrend<=0; - [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(1:(LevelPixels+30))); %10 - else - [pk,lk] = findpeaks(IntensitiesAverFin_2{jjj}(1:(LevelPixels+30))); %10 - end - [Height(jjj),pkH]=max(pk); - if max(pk)>=10; % error cleaning %30 - qH=lk(pkH); - Metr_fit_H(jjj)=polyval(polypar_Metr,qH); - end - plot(ax, qH, Height(jjj), 'om', 'linewidth', 2) - end - - elseif D_num==2 - LevelPixels=MeterScale(1); % x level in pixels in the original image - if jjj == 1 - [pk,lk] = findpeaks(-IntensitiesAverFin{jjj}(LevelPixels:end)); %10 - [Height(jjj),pkH]=max(pk); - qH=LevelPixels+lk(pkH); - Metr_fit_H(jjj)=polyval(polypar_Metr,qH); - plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) - else - if waytrend<=0; - [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - else - [pk,lk] = findpeaks(IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - end - [Height(jjj),pkH]=max(pk); - qH=LevelPixels+lk(pkH); - Metr_fit_H(jjj)=polyval(polypar_Metr,qH); - if max(pk)<30; % error cleaning %30 - qH=NaN; - Metr_fit_H(jjj)=NaN; - end - plot(ax, qH, Height(jjj), 'or', 'linewidth', 2) - end - end - - if jjj == 1 - [pk2,lk2] = findpeaks(-IntensitiesAverFin{jjj},'MinPeakProminence',5); % Small peaks at the bubble/liquid interface - - [pk3,lk3] = findpeaks(-IntensitiesAverFin{jjj},'MinPeakProminence',5,'MinPeakDistance',30); % Throw out small random peaks in the liquid, peaks far apart cca 1cm - [one,nqq]=size(lk3); - [one,npp]=size(lk2); - - if npp==0 - pk2=NaN; - lk2=NaN; - elseif nqq==0 - pk3=NaN; - lk3=NaN; - end - - for qqq=1:1:nqq - for ppp=1:1:npp - if lk3(qqq)==lk2(ppp) - pk2(ppp)=NaN; - lk2(ppp)=NaN; - end - end - end - - % % plot(lk2,abs(pk2),'om','linewidth',2) - hold on - - [Bottom(jjj),pk2B]=max(abs(pk2)); % For 1-4 files - qB=lk2(pk2B); % For 1-4 files - - Metr_fit_B(jjj)=polyval(polypar_Metr,qB); - if Metr_fit_B(jjj)>=(Metr_fit_H(jjj)-2) % Throw out the bubble/liquid interface if it is above the surface, 2cm 2D interface - Metr_fit_B(jjj)=NaN; - qB=NaN; - elseif Bottom(jjj)<=(max(abs(pk))+min(abs(pk)))*0.62 % 0.65 is an estimate of how much intensity the bubbles need - Metr_fit_B(jjj)=NaN; % For 1-4 files - qB=NaN; - end - plot(ax, qB, Bottom(jjj), 'ob', 'linewidth', 2) - else - if D_num==1 - LevelPixels=MeterScale(1+(1000-LevelNum)/100); % x level in pixels in the original image - if waytrend<=0; - [pk2,lk2] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - else - [pk2,lk2] = findpeaks(IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - end - [Bottom(jjj),pk2B]=max(pk2); - qB=LevelPixels+lk2(pk2B); - Metr_fit_B(jjj)=polyval(polypar_Metr,qB); - if max(pk2)<=45; % error cleaning - qB=NaN; - Metr_fit_B(jjj)=NaN; - end - plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) - elseif D_num==2 - LevelPixels=MeterScale(1); % x level in pixels in the original image - if waytrend<=0; - [pk2,lk2] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - else - [pk2,lk2] = findpeaks(IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 - end - [Bottom(jjj),pk2B]=max(pk2); - qB=LevelPixels+lk2(pk2B); - Metr_fit_B(jjj)=polyval(polypar_Metr,qB); - if max(pk2)<=20; % error cleaning - qB=NaN; - Metr_fit_B(jjj)=NaN; - end - plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) - end - end - - writematrix(["ImageName" "Date" "Time [s]" "Intensities Height [-]" "Intensities Bottom [-]" "Height [cm]" "Bottom [cm]" "Level [cm]"], ResFile, "Sheet", SelectedDirectory{iii}, "Range", "A1:H1"); - writematrix([ImageName string(Date(jjj)) seconds(Time(jjj)) Height(jjj) Bottom(jjj) Metr_fit_H(jjj) Metr_fit_B(jjj) LevelNum], ResFile, "Sheet", SelectedDirectory{iii}, "Range", ['A' num2str(file_ind+1) ':H' num2str(file_ind+1)]); - - end % jjj, Cycles for figures files - - hf4=figure ('Name','Velocity','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters'); - hp1=plot(seconds(Time), Metr_fit_H,'-or','linewidth',2); % [1 startFile:step:nFFiles] - hold on - hp2=plot(seconds(Time), Metr_fit_B,'-ob','linewidth',2); - hold on - hp3=plot(seconds(Time),LevelNum*ones(size(Time)),'-og','linewidth',2); - - xlabel('time [s]','FontWeight','bold'); - ylabel('position [cm]','FontWeight','bold'); - grid('on'); - [legend_h,object_h,plot_h,text_strings] = legend([hp1,hp2,hp3],'Height', 'Bottom', 'Level','Location','southeast' ); - set(legend_h, 'Box', 'off', 'FontSize',7) +% Initiation from the first file + ImageName = FFiles(1).name; + start_time = duration([(ImageName(8:9)) ':' (ImageName(10:11)) ':' (ImageName(12:16))],'Format',infmt); + Figure = imread([FFiles(1).folder '/' ImageName]); + ContrastFigure = imadjust(Figure); % Adjust the contrast of the image using imadjust. + D_num=str2double(SelectedDirectory{iii}(21)); % position of camera -%-------------------------------------------------------------------------- - print ('-dpng', '-r1200', 'Velocity.png') -%-------------------------------------------------------------------------- + [image_width, image_height] = size(Figure); + sumfig = zeros(image_width, image_height); + minfig = Figure; + maxfig = Figure; +% load of all files in cycles + step=1; + startFile= 1; %945; %200 (20. ) + endFile= numel(FFiles); %nFFiles; %1000; %325 (20.) + nFFiles=endFile; % Attention!!! + wait_bar = waitbar(0, ''); + set(gca(wait_bar).Title, 'Interpreter', 'none'); + for jjj=startFile:step:nFFiles % Cycles for figures files + ImageName = FFiles(jjj).name; + Figure = imread([FFiles(jjj).folder '/' ImageName]); + + waitbar(jjj/nFFiles, wait_bar, ['Preproccessing images from meassurement ' num2str(iii) '/' num2str(nSelectedDirectory)]); + + sumfig = sumfig + double(Figure); + minfig = min(minfig, Figure); + maxfig = max(maxfig, Figure); + end % jjj, Cycles for figures files - %%xlswritefig(hf4, ResFile, SelectedDirectory{iii}, 'J2') + close(wait_bar); + + meanfig = uint8(sumfig ./ nFFiles); + changefig = maxfig - minfig; + + figure + subplot(2,2,1); + title('Pixel maxima'); + imshow(maxfig); + subplot(2,2,2); + title('Pixel minima'); + imshow(minfig); + subplot(2,2,3); + title('Pixel means'); + imshow(meanfig); + subplot(2,2,4); + title('Difference between max and min'); + imshow(changefig); end % iii, Cycles for directories with files diff --git a/get_representative_intensities.m b/get_representative_intensities.m deleted file mode 100644 index 1ca91b9..0000000 --- a/get_representative_intensities.m +++ /dev/null @@ -1,20 +0,0 @@ -function intensities = get_representative_intensities(Figure) - - [p,q]=size(Figure); - ContrastFigure = imadjust(Figure); % Adjust the contrast of the image using imadjust. - -% Figure bands for average compution intensity, without the bands with hole and meter - - ContrastFigure1=ContrastFigure(floor(p*1/16):floor(p/8+p*1/16-3), 1:q); - [p1,q]=size(ContrastFigure1); - ContrastFigure2=ContrastFigure(floor(p/2+p/32):floor(p*3/4-p*1/16-5), 1:q); - [p2,q]=size(ContrastFigure2); - ContrastFigure3=ContrastFigure(floor(p*3/4+p*1/16):floor(p-p*1/16), 1:q); - [p3,q]=size(ContrastFigure3); - - ContrastFigureFin(1:p1,1:q)=ContrastFigure1; - ContrastFigureFin(p1+1:p1+p2,1:q)=ContrastFigure2; - ContrastFigureFin(p1+p2+1:p1+p2+p3,1:q)=ContrastFigure3; - - intensities = mean(ContrastFigureFin); -end diff --git a/meter.m b/meter.m deleted file mode 100644 index 08440d6..0000000 --- a/meter.m +++ /dev/null @@ -1,123 +0,0 @@ -function [MeterScale, polypar_Metr] = meter(SelectedDirectory, ContrastFigure, ResFile) - - [p, q] = size(ContrastFigure); -% Meter - D_num=str2double(SelectedDirectory(21)); % position of camera - - reply = input('Is this a NEW EXPERIMENT that does not yet have calculated parameters for the cm scale? (y/n): ','s'); % y, n Selects where to find parameters for the cm scale. Either in the array or guess them. - if strcmp(reply,'n') - AxisIntensArray=[22,22,22,22,25,27,7,7,7,7,7,23,3,20,11,2,4,19,6,25,3]; % this needs to be guessed - AxisIntensUpArray=[60,60,65,65,34,5,29,29,29,29,29,22,26,2,27,2,28,2,29,2,29]; % this needs to be guessed - AxisEmptyArray=[190,190,190,190,200,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190]; % this needs to be guessed 190 - LevelMeterArray=[0.95,0.95,0.95,1,0.11,0.8,0.2,0.2,0.2,0.1,0.29,0.9,0.39,0.9,0.39,0.6,0.29,0.9,0.25,0.7,0.27]; - AxisIntens=AxisIntensArray(Selected-13); % The number of all files minus 9 in which there is no data - AxisIntensUp=AxisIntensUpArray(Selected-13); - AxisEmpty=AxisEmptyArray(Selected-13); - LevelMeter=LevelMeterArray(Selected-13); - elseif strcmp(reply,'y') - AxisIntens=25; % 1.- 4. =22; 5. - 29 6.-27 7.8.9.11.11.-7 12.=23 13.=3 % Right this needs to be guessed - AxisIntensUp=2; % 3. = 65; 1. a 2. = 60; 5. - 34 6. a 7.8.9.10.11. = 29 12.=22 13.=26 % Left this needs to be guessed - AxisEmpty=190; % 5. = 200; 6. 7.8.9.10.11.12.13 = 190 % this needs to be guessed 190 - LevelMeter=0.7; % 5. = 0.11, 4. = 1; 1., 2. a 3. = 0.95, 6. =0.9; 7.8.9.=0.2 10.=0.1 11.=0.29 12.=0.9 13.=0.39 % number on the meter so that the left dash is above the surface and the right is below the surface - end - - Meter=ContrastFigure(floor(p*3/4-p*1/16+p*1/64):floor(p*3/4+p*1/64), 1:q); - ContrastMeter = imadjust(Meter); - [r,s]=size(ContrastMeter); - ContrastMeterMid=ContrastMeter(floor(end/2),:); - - hf1=figure ('Name','Contrasted meter','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters'); - imshow(ContrastMeter) - hold on - plot(ContrastMeterMid,'-m','linewidth',2) - hold on - - for kkk=2:1:q - if kkk<(1-LevelMeter)*q && ContrastMeterMid(kkk)>AxisIntensUp % looks for intensity minima for dashes on the axis above the level, Left - ContrastMeterMid(kkk)=0; - elseif kkk>=(1-LevelMeter)*q && ContrastMeterMid(kkk)>AxisIntens % looks for intensity minima for dashes on the axis under the level, Right - ContrastMeterMid(kkk)=0; - else - ContrastMeterMid(kkk)=1; - end - if ContrastMeterMid(kkk) == ContrastMeterMid(kkk-1) % looking for the right side of the peak - ContrastMeterMid(kkk-1)=0; - end - end - for mmm=q:-1:AxisEmpty - if ContrastMeterMid(mmm)==1 % erases the peaks (written numbers) to the left of the dashes on the axis - ContrastMeterMid((mmm-AxisEmpty):mmm-1)=0; - mmm=mmm-AxisEmpty; - end - end - ooo=1; - for nnn=1:1:q - if ContrastMeterMid(nnn)==1 % Writes x places of dashes on the axis - MeterScale(ooo)=nnn; - ooo=ooo+1; - end - end - - if D_num==1 - plot(MeterScale, floor(r/2) * ones(10, 1),'oc','linewidth',2) - elseif D_num==2 - plot(MeterScale(1:end-1), floor(r/2) * ones(8, 1),'oc','linewidth',2) - end -%-------------------------------------------------------------------------- - print ('-dpng', '-r1200', ['Contrasted_meter.png']) -%-------------------------------------------------------------------------- - - - hf2=figure ('Name','Intensity minima for dashes on the axis','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters'); - plot(ContrastMeterMid,'-m','linewidth',2) - - xlim([1,q]); - ylim([0,1]); -%-------------------------------------------------------------------------- - print ('-dpng', '-r1200', ['Intensity_places_dashes.png']) -%-------------------------------------------------------------------------- -clear Meter -clear ContrastMeter -clear ContrastMeterMid - -% Calculation of the actual position in mm using the scale of the meter - - hf3=figure ('Name','Dashes scale','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters'); - if D_num==1 - plot(MeterScale,[1000;900;800;700;600;500;400;300;200;100],'ob','linewidth',2) - hold on - polypar_Metr = polyfit(MeterScale,[1000;900;800;700;600;500;400;300;200;100],2); - elseif D_num==2 - plot(MeterScale(1:end-1),[1800;1700;1600;1500;1400;1300;1200;1100],'ob','linewidth',2) - hold on - polypar_Metr = polyfit(MeterScale(1:end-1),[1800;1700;1600;1500;1400;1300;1200;1100],2); - end - no_layer_fit=1: 1 : q; - Metr_fit=polyval(polypar_Metr,no_layer_fit); - plot(no_layer_fit,Metr_fit,'-r','linewidth',2); - hold on - if D_num==1 - xlim([0,q]); - ylim([0,1200]); - elseif D_num==2 - xlim([0,q]); - ylim([0,2000]); - end -%-------------------------------------------------------------------------- - print ('-dpng', '-r1200', 'Dashes_scale.png') -%-------------------------------------------------------------------------- - - writematrix("Contrasted meter", ResFile, "Sheet", append("Met ", SelectedDirectory), "Range","A2"); %[cell2mat(SelectedDirectory(iii)) ': Meter scale'],'A1'); ['Meter scale ' num2str(iii)] - %%xlswritefig(hf1, ResFile, ['Met ' cell2mat(SelectedDirectory(iii))] , 'A4') - writematrix("Intensity: places of dashes on the axis", ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "A6"); - %%xlswritefig(hf2, ResFile, ['Met ' cell2mat(SelectedDirectory(iii))], 'B8') - writematrix("Dashes scale", ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "K6"); - %%xlswritefig(hf3, ResFile, ['Met ' cell2mat(SelectedDirectory(iii))], 'L8') - writematrix(["Meter Scale" "Dashes scale"], ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "A28"); - writematrix(["AxisIntens" "AxisIntensUp" "AxisEmpty" "LevelMeter"], ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "D28"); - if D_num==1 - writematrix([MeterScale' [1000;900;800;700;600;500;400;300;200;100]], ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "A29"); - elseif D_num==2 - writematrix([MeterScale(1:end-1)' [1800;1700;1600;1500;1400;1300;1200;1100]], ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "A29"); - end - writematrix([AxisIntens AxisIntensUp AxisEmpty LevelMeter], ResFile, "Sheet", append("Met ", SelectedDirectory), "Range", "D29");