Hi, I wish to output my new modified images to a new directory, but I got this error "Struct contents reference from a non-struct array object". Im sorry if there is more than one problem needs to be fixed here. I tested the first loop was working well, but not for the second loop. I guess the problem comes from the loop for writing images to a new directory. Thanks for any suggestion in advance.
img_folder='/Users/MATLAB/Faces';imgs =dir(fullfile(img_folder, '*.jpg'));%output folder
distFolder = '/Users/MATLAB/Faces/New';if isdir(distFolder) rmdir(distFolder, 's');endmkdir(distFolder);for i=1:length(imgs) %loop for modifed images
imgsName = imgs(i).name; fullName=fullfile(img_folder,imgsName); img = im2uint8(imread(imgsName)); img = img(:,:); image_thresholded = zeros(size(img)); for ii=1:size(img,1) for jj=1:size(img,2) pixel=img(ii,jj); if pixel<10 new_pixel=11; elseif pixel>240 new_pixel=239; else new_pixel = pixel; end image_thresholded(ii,jj)=new_pixel; end end for k= 1:length(image_thresholded) % loop reads the new images into new directory
newimgsName= image_thresholded(k).name; thresholdImg = (sprintf('%s.jpg', k)); fulldestination = fullfile(distFolder, newimgsName); imwrite(image_thresholded,thresholdImg,fulldestination,'jpg') endend
Best Answer