My batch image processing is only processing the last image of the folder!

3 views (last 30 days)
myFolder='C:\Users\adria\MATLAB Drive\HE_ImageData'
S= dir(fullfile(myFolder,'*.tiff'));
for k = 1:
F = fullfile(myFolder,S(k).name);
fprintf(1, 'Reading %s\n', F);
I = imread(F);
% figure
% imshow(I)
end
2. Images properties
% 3.1 Reading and getting the information about the image
% 3.2 Separating the image beetween a map and a RGB channels
Redchannel = I(:,:,1);
% Greenchannel I(:,:,2);
% Bluechannel = I(:,:,3);
% 3.3 Histograms for all three channels
imhist(Redchannel);
title('Red Channel Histogram')
% imhist(REDchannel);
Hello, I am having the following issue, I am doing a batch processing for 40 images. I have already writen the code, however, when I try to apply the code for all the 40 images, as you see I have to separate the images into three channels, it only process image number 9. The images are being read 1,10(...)19, 2,21 (...)29, 3,31(..) 4, 5 , 6, 7 , 8, 9 being 9 the only image processed. I have tried everything. I have read a lot here in the forum trying to solve this issue. Can someone help me, so I can just have all the images processed?

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 1 Jun 2021
You're calculating imhist() outside of the for loop that is why only the last read image is being processed. You need to use the "processing code" inside the for loop. The below code might help.
myFolder = "C:\Users\adria\MATLAB Drive\HE_ImageData";
S = dir(fullfile(myFolder, '*.tiff'));
for idx = 1:numel(S)
fullFileName = fullfile(myFolder, S(idx).name);
fprintf(1, 'Reading %s\n', fullFileName);
img = imread(fullFileName);
redChannel = img(:, :, 1);
figure
imhist(redChannel)
title(['Image ', num2str(idx), ' Red Channel Histogram'])
end
  3 Comments
Sarah DS
Sarah DS on 6 Jun 2021
Hello Sir, I just have one last question and I hope you don't mind.
I am tryting to calculate the area in cm of a blood stain in a gauze from the batch processing, however the end result is not what I need. I have read an apparently the number given in a pixel list and I need to do some sort of calibration in which I am not entirely sure how. I have read the imageAnalist about the theme but I still don't comprehend on how to do so. Can you guide me please?
I have the dimensions of the gauze which are 9.5 cm *3.5 cm. Below is the result of the area I get for the image.
% Calculating the area of the blood stains
statsred = regionprops('table',Rederode,'Centroid', 'MajorAxisLength','MinoraxisLength')
centers = statsred.Centroid;
diameters = mean([statsred.MajorAxisLength statsred.MinorAxisLength],2);
Redradius = diameters/2;
area = pi*Redradius.^2
Amit
Amit on 6 Jun 2021
For calibrating area you need to know magnification of your image, or ppi (pixel per inches ) or pixel per sqmm of image.
having this information you can detetermine size of complete image in mm or micron and according you can measure/calibrate any unit length or dimensions of any region.
You can try above approach which should work for you.
Else, you can send me your image in actual scale on amit.kenjale@gmail.com, will check image and write source code for both calibration and measurement of images.

Sign in to comment.

More Answers (0)

Categories

Find more on Biomedical Imaging 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!