how can i save the data after processing sequence of images?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Gaurav Garg
el 23 de Sept. de 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 comentarios
Gaurav Garg
el 23 de Sept. de 2020
That's because img_fullfile is not a string. You can convert it to string by data type conversion, taking help from here.
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!