MATLAB Answers

how process sequence of the images in a loop without overwriting

3 views (last 30 days)
Akhir Shaik
Akhir Shaik on 25 Feb 2020
Commented: Akhir Shaik on 10 Mar 2020
here, i am solving around 20000 images at once but the output i'm getting is only the last iamge.
here is the code i got from the Matlab Answers, but also it didn't work can anyone help me.

  3 Comments

darova
darova on 26 Feb 2020
Please explain more. You have 20k images. What are you trying to do with them? And the result image is only one
Akhir Shaik
Akhir Shaik on 26 Feb 2020
here, i need to find the breakup length, need to solve 20k images at once and need to save value in numerical or dat file.
the image processing code is ok. if i solve for 1 images i got the answer but solving for 20k images it is considering only the last image file in the folder.
Stephen Cobeldick
Stephen Cobeldick on 3 Mar 2020
Original Question: "how process sequence of the images in a loop without overwriting"
here, i am solving around 20000 images at once but the output i'm getting is only the last iamge.
here is the code i got from the Matlab Answers, but also it didn't work can anyone help me.
myFolder = 'E:\IMAGES\100k\flip';
if exist(myFolder, 'dir') ~= 7
Message = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(Message));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for i = 1:length(jpegFiles)
fileName = sprintf('%5.5d.jpg', i);
piccell{i} = imread(fileName);
end
grayImage = imread(fileName);
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
highThreshold = 150;
binaryImage = grayImage <= highThreshold;
binaryImage = bwareafilt(binaryImage, 1);
binaryImage = imfill(binaryImage, 'holes');
bottomLine = zeros(rows, 1);
for col = 1 : columns
thisColumn = binaryImage(:, col);
lastLine = find(thisColumn, 1, 'last');
if ~isempty(lastLine)
bottomLine(col) = lastLine;
end
end
meanbottomLine = mean(bottomLine(bottomLine>0));
save bkl_.dat meanbottomLine -ascii

Sign in to comment.

Answers (1)

Benjamin Großmann
Benjamin Großmann on 26 Feb 2020
Have a look at your first for loop. Here you are generating a char called fileName which is overwritten in every loop count. furthermore, this loop is unnecessary since you already have your file names in the struct array jpegFiles.
Try to use
fileNameCell = {jpegFiles.name};
to get a cell array of file names. Then write a function which does your image manipulation for one file. Finally, call your function with cellfun and the fileNameCell to apply the image manipulation to every file in the cell.
You can also have a look at the imageSet class.

  8 Comments

Show 5 older comments
Akhir Shaik
Akhir Shaik on 27 Feb 2020
i followed in your suggestion. i got an errror.
Not enough input arguments.
Error in findmeanbottomline (line 3)
img = imread(img_fullfile);
Benjamin Großmann
Benjamin Großmann on 9 Mar 2020
Please put a breakpoint in line 3 of the function, then run the script and post the contents of img_fullfile after the breakpoint was reached
Akhir Shaik
Akhir Shaik on 10 Mar 2020
i added the breakpoint and tried same error.
not enough input arguments.
i tried to solve this by using the loops and function file but not not working getting only the last image answer.
help pls,

Sign in to comment.

Sign in to answer this question.


Translated by