필터 지우기
필터 지우기

How to store the pixel information of each images in a folder into separate variables?

조회 수: 1 (최근 30일)
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?

채택된 답변

Image Analyst
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
  댓글 수: 1
Md Farhad Mokter
Md Farhad Mokter 2019년 5월 28일
Thank you so much for your quick answer. But I have a large amount of images in the folder and I need to find the ratio of black pixels to other pixels for each image. repeating the process for all images will be hectic Thats why i need variables for each images. I Could not think of other ways. Please let me know if you have better alternatives.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by