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

조회 수: 5 (최근 30일)
basha Shaik
basha Shaik 2020년 9월 20일
댓글: Gaurav Garg 2020년 9월 23일
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

답변 (1개)

Gaurav Garg
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
basha Shaik
basha Shaik 2020년 9월 23일
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 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 CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by