Trouble importing file of image to run through function, then combining/exporting as a file

조회 수: 1(최근 30일)
I am writing a function that takes an images and converts it to BW. I would like to make my function so that it takes in a file of images, runs through the function (making every image BW), and combines the new BW images into a new file. What should I do?
Here is my working BW function MidAirBW:
midAirImage = imread("MidAirTest.jpg");
midAirImage = rgb2gray(midAirImage);
bwImage = imbinarize(midAirImage,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);
This is what I tried for the file function:
D = 'Video2 gif stack';
S = dir(fullfile(D, 'name*.jpg'))
for k = 1:numel(S)
F = fullfile(D, S(k).name);
I = MidAirBW(F)
imwrite(I, 'BW edited images')


Raunak Gupta
Raunak Gupta 2020년 8월 12일
Hi Ashley,
I assume by combining you means saving the images with distinct name into the same folder or different folder. You can probably rename the files with string like “_BW_edit” to every image name last part. Below code might help.
for k = 1:numel(S)
F = fullfile(D, S(k).name);
I = MidAirBW(F);
imwrite(I, strcat(F(1:end-4),'_BW_edit.jpg'));

Community Treasure Hunt

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

Start Hunting!

Translated by