Reading the arranged file name

2 views (last 30 days)
Ravin Rayeok
Ravin Rayeok on 23 Oct 2020
Commented: Ameer Hamza on 23 Oct 2020
Hey need some assitance here,
I have 150 Images with the name of 1 until 150.
My code read the image as 1 10 100 101 etc instead of 1 2 3
So, instead of renaming my images 001 002 003 etc.
How to create a code to read and process my images in order of 1 2 3 4.... n
image_folder = 'F:\Microfluidic_Experments_Back_Up_May_2020\GEA\2020-09-02_Gea_aqeous_phase_10cP_Oil\2020-09-02_10-57-35'; % 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');
%p=ginput(2)
K=imcrop(our_images,[1343 8 5581 5496]);
%imshow(K);
red=K(:,:,1);
green=K(:,:,2);
blue=K(:,:,3);
%d=impixel(K); %Manually Show Pixel Value
% Get the Water mask
OilMask = red > 180 & green > 170 ;
% Get the Bubble mask
PolyMask = red > 210 & green > 215 & blue > 170;
% Make Water mask green
red(OilMask) = 0;
green(OilMask) = 255;
blue(OilMask) = 0;
% Make the Bubble mask blue
red(PolyMask) = 0;
green(PolyMask) = 0;
blue(PolyMask) = 255;
% Recombine separate color channels into a single, true color RGB image.
rgbImage2 = cat(3, red, green, blue);
%subplot(2, 1, 2);
%Water Pixel Sum
OilPixels = rgbImage2(:,:,1) == 0 & rgbImage2(:,:,2) == 255 & rgbImage2(:,:,3) == 0;
numOilPixels(n) = sum(OilPixels(:));
%Bubble Pixel Sum
PolyPixels = rgbImage2(:,:,1) == 0 & rgbImage2(:,:,2) == 0 & rgbImage2(:,:,3) == 255;
numPolyPixels(n) = sum(PolyPixels(:));
imshow(rgbImage2);
% numOil(n) = numel(OilPixels);
% numPoly(n) = numel(PolyPixels);
%SAVING FIGURE
path='F:\Microfluidic_Experments_Back_Up_May_2020\GEA\2020-09-02_Gea_aqeous_phase_10cP_Oil_MATLAB_RESULT\Binary Image';
saveas(figure(n),fullfile(path,['Figure' num2str(n) '.jpeg']));
%imshow(our_images) % Show all images
close
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 23 Oct 2020
  3 Comments
Stephen23
Stephen23 on 23 Oct 2020
Edited: Stephen23 on 23 Oct 2020
"How doyou put it in the code?"
The M-file itself, the HTML documentation, and also the linked webpage all have plenty of examples, so you should not have any difficulty finding an example similar to your task and following it. It can be called just like any other function.
"I tried and it said undefined function or variable"
Just like all other code available on MATLAB File Exchange you will need to click the big blue "Download" button (top right corner of the page), then unzip the file into your MATLAB Search Path (e.g. the current directory). Then you will be able to use it, following its documentation of course.
I strongly recommend using natsortfiles instead of natsort.
Ameer Hamza
Ameer Hamza on 23 Oct 2020
@Stephen Cobeldick: Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!