how can i save the data after processing sequence of images?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Gaurav Garg
2020-9-23
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 个评论
Gaurav Garg
2020-9-23
That's because img_fullfile is not a string. You can convert it to string by data type conversion, taking help from here.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!