The reason I'm trying to run this code on a windows is that, this windows machine is a 128gb workstation. And I've 14 sets of 6000 images, that I need to process. I had used my personal laptop to develop and test the code and then I'm trying to get things done in my lab's workstation.
Background Subtraction In Images:
14 次查看(过去 30 天)
显示 更早的评论
Dear all,
I had written a code which was constructing A background image from a given set of images and then subtracting it so as to remove noise. Now it was working perfectly on my macbook, but when I'm trying to run on windows it's giving me an error.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/424688/image.jpeg)
I'm using sprintf to keep the length of the string constant. like img_00001, img_0002, ....., img_00011, ... img00100, .... etc. This insures that images are properly ordered. Can anyone help me out in figuring, what's the error here. Why it is not working on windows when it was working on MACos.
Thanks,
Matlab Code:
%% Creating And Subtracting a Background Image:
clc ; close all ; clear ;
%%
% Get the names of files to be Imported:
% Directory for importing the images:
import_directory = uigetdir('Locate Folder for Input Images') ;
image_extension = '*.tif' ;
direc = dir([import_directory , filesep , image_extension] ) ;
filenames = {} ;
[filenames{1:numel(direc) , 1}] = deal(direc.name) ;
filenames = sortrows(filenames) ;
num_of_images = length(filenames) ;
%% Preallocating Space for Images:
pj = uint16(zeros(size(imread([import_directory , filesep , filenames{1}])))) ;
% Select Directory For Exporting the Images:
export_directory = uigetdir('Locate Folder for Output Images') ;
tic
for i = 1:num_of_images
name2 = sprintf([export_directory , filesep , 'Background_Subtracted_Output_File_%6.6i.tif'] , i) ;
imwrite(pj , name2) ;
end
t(1) = to
采纳的回答
Bjorn Gustavsson
2020-11-23
Instead of using sprintf to generate the full (or relative, doesn't matter which) path to your images you should use fullfile. That should be a robust way of generating the full filename with the correct filesep, but without creating the error you've run into.
Also note that this is not the error you get stuck on, the error is that imwrite gets confused about the image-format. That might be because of the peculiar filename youve gotten. Exactly what causes that is tricky to check, it should work with a filename with the .tif extension, your filename should have a correct numbering from your '%6.6i', it might be because imwrite for some reason combines "\" and "A" in your path into "\A" and gets distracted?
HTH
4 个评论
更多回答(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!