how can i save the data after processing sequence of images?

2 visualizzazioni (ultimi 30 giorni)
i have a lot of images, for example 0001,0002.....10000, after processing the result data will be in .dat file it is just getting overwritten and finally i get only 10000 image data. can anyone help me from this?
clearvars, close all
clc
myFolder = '';
filePattern = fullfile(myFolder, '*.jpg'); % my images are in subfolders, so i changed your filepattern
jpegFiles = dir(filePattern);
% For simplicity of this example, lets use the full/absolute path to the images
fileNameCell = fullfile({jpegFiles.folder}, {jpegFiles.name});
% Call the function with cellfun; returns a cell with each entry corresponing to the fileNameCell
meanbottomlineCell = cellfun(@findmeanbottomline, fileNameCell);
function meanbottomLine = findmeanbottomline(img_fullfile)
img = imread(img_fullfile);
[rows, columns, numberOfColorChannels] = size(img);
if numberOfColorChannels > 1
grayImage = rgb2gray(img);
else
grayImage = img;
end
highThreshold = 210;
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));
% Put red line there at that level.
hold on;
line([1, columns], [meanbottomLine, meanbottomLine], 'Color', 'r', 'LineWidth', 2);
caption = sprintf('Cleaned Binary Image with last line at an average of %.1f', meanbottomLine);
save 123.dat meanbottomLine -ascii
end

Risposte (1)

Gaurav Garg
Gaurav Garg il 23 Set 2020
Hey Shaik,
You can save the data to a new file for each image rather than over-writing the '123.dat' file.
For this, you can use
save(img_fullfile, meanbottomLine)
  2 Commenti
basha Shaik
basha Shaik il 23 Set 2020
Hello Gaurav, i tried this i got error. i am solving around 10000 images i need to save data. so, i use dat file.
Error using save
Must be a string scalar or character vector.
Error in Untitled2>findmeanbottomline (line 42)
save(img_fullfile, meanbottomLine)
Gaurav Garg
Gaurav Garg il 23 Set 2020
That's because img_fullfile is not a string. You can convert it to string by data type conversion, taking help from here.

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by