Storing calculated data in loop

1 visualización (últimos 30 días)
Ravin Rayeok
Ravin Rayeok el 8 de Jun. de 2020
Comentada: Ravin Rayeok el 8 de Jun. de 2020
Hello everyone!
I need some assistance here.
I've calculated amounts of white pixels from an image, now i wanna store that value and then continue to the next image.
Here is my unfinished loop code:
How to store data from that numWhitePixel fucntion for multiple images?
image_folder = '/Volumes/Untitled/MATLAB copy/Foam_Experiments_inj_pressure/V3 @300mbar/2019-11-21_10-31-53'; % Enter name of folder from which you want to upload pictures with full path
filenames = dir(fullfile(image_folder, '*.jpg')); % read all images with specified extention, its jpg in our case
total_images = numel(filenames); % count total number of photos present in that folder
for n = 1:total_images
f= fullfile(image_folder, filenames(n).name); % it will specify images names with full path and extension
our_images = imread(f); % Read images
figure (n) % used tat index n so old figures are not over written by new new figures
J = imrotate(our_images,90,'bilinear','loose');
%imshow(J);
%p=ginput(2)
K=imcrop(J,[0.5 1220.5 5504 5810]);
%imshow(K);
red=K(:,:,1);
green=K(:,:,2);
blue=K(:,:,3);
%
% % Define thresholds for channel 1 based on histogram settings
channel1Min = 225.000;
channel1Max = 255.000;
%
% % Define thresholds for channel 2 based on histogram settings
channel2Min = 210.000;
channel2Max = 252.000;
%
% % Define thresholds for channel 3 based on histogram settings
channel3Min = 210.000;
channel3Max = 255.000;
% % Create mask based on chosen histogram thresholds
BW = (K(:,:,1) >= channel1Min ) & (K(:,:,1) <= channel1Max) & ...
(K(:,:,2) >= channel2Min ) & (K(:,:,2) <= channel2Max) & ...
(K(:,:,3) >= channel3Min ) & (K(:,:,3) <= channel3Max);
% % % Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
%fill=imfill(BW,'holes');
morph=bwmorph(BW,'erode');
dilate=bwmorph(morph,'dilate',1);
BW2 = bwareaopen(dilate,20);
numWhitePixels = numel(BW2)
end
Thank You!

Respuesta aceptada

David Hill
David Hill el 8 de Jun. de 2020
Just index it with your for-loop:
numWhitePixels(n) = numel(BW2);
  1 comentario
Ravin Rayeok
Ravin Rayeok el 8 de Jun. de 2020
well... didn't think about that. Thanks a lot !

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by