How to store the pixel information of each images in a folder into separate variables?
1 回表示 (過去 30 日間)
古いコメントを表示
Md Farhad Mokter
2019 年 5 月 28 日
コメント済み: Md Farhad Mokter
2019 年 5 月 28 日
I have a code that counts black pixels of a given image and stores that in a variable. I want to count and store black pixels from each images of a folder into separate variables.
I = imread('8.JPG');
bw = imbinarize(I);
figure; imshow(bw);
ctr= 0;
for i = 1:224
for j =1:224
if bw(i,j) ==0
ctr = ctr + 1;
end
end
end
How can I implement this code using loop for all the images in a directoy so thati can have a variable that contains numbers of black pixels of each image?
0 件のコメント
採用された回答
Image Analyst
2019 年 5 月 28 日
How about using save()?
I = imread('8.JPG');
bw = imbinarize(I);
numBlackPixels = nnz(~bw);
folder = 'c:/whereverYouWant';
baseFileName = 'MyData.mat';
fullFileName = fullfile(folder, baseFileName);
save(fullFileName, 'numBlackPixels');
No for loop is needed.
Repeat for all your other images.
See the FAQ for code samples to process a sequence of images: The FAQ
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!