Reading the arranged file name

조회 수: 2 (최근 30일)
Ravin Rayeok
Ravin Rayeok 2020년 10월 23일
댓글: Ameer Hamza 2020년 10월 23일
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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 23일
  댓글 수: 3
Stephen23
Stephen23 2020년 10월 23일
편집: Stephen23 2020년 10월 23일
"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 2020년 10월 23일
@Stephen Cobeldick: Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by