imwrite does not save file in specified folder :(
15 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have searched the internet and Matlab Answers website and could not find an answer that worked for my problem, so I am asking here.
I am color-correcting the white balance of a jpeg image using the code below. I use the Image Processing Toolbox functions imread to open the raw image and imwrite to save the new color-corrected image (but with a slighty different name) in the same folder.
However, when I run the code and check the folder, no new files have been created. I tried re-defining the folder path within the for loop, and then within the imwrite function itself, but neither has worked. I also tried saving the image as a .jpg or .png or saving with the same name into a new empty folder, but these didn't work either.
I don't know why imwrite is not creating a new file, and any help would be much appreciated!!
newpath = 'C:\Users\551\Documents\raw-data\';
userpath(newpath)
file = dir('1.1-ERG-T2.jpeg');
for k = 1:length(file)
I = imread(file(k).name);
w1=3440:3500; w2=554:742;
R = I(w1,w2,1);
R = reshape(double(R),size(R,1) * size(R,2),1);
G = I(w1,w2,2);
G = reshape(double(G),size(G,1) * size(G,2),1);
B = I(w1,w2,3);
B = reshape(double(B),size(B,1) * size(B,2),1);
I(:,:,1) = double(I(:,:,1)) + 255-floor(mean(R));
I(:,:,2) = double(I(:,:,2)) + 255-floor(mean(G));
I(:,:,3) = double(I(:,:,3)) + 255-floor(mean(B));
imwrite(I,['new_' file(k).name(1:end-4) '.jpeg']); % add "new_" in the filename to avoid replacing raw image
end
0 件のコメント
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!