I am getting the same processed image result from easch iteration of the loop.I want to get the respective processed image from each iteration of the loop.
2 次查看(过去 30 天)
显示 更早的评论
I have an ultrasound image consisting of labeles.I have removed the labeles using the code below.however i got the same processed image from each iteration of the loop.i want to get 6 processed images that corresspond to the original image.
clearvars
myDir = uigetdir('*.m'); %gets directory
myFiles = dir(fullfile(myDir,'*.png')); %gets all png files in struct
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
%[imData, Fs] = imread(fullFileName);
FName= myFiles.name;
img = imread(FName);
img = im2gray(img); % need to work on the right image
% use the actual image dimensions
[nrows,ncols,~] = size(img);
for row = 1:nrows
for col = 1:ncols
% image origin is NW corner, so a line which points from SW to NE
% actually has negative slope!
if row < (-0.77*col + 253.64)
img(row,col) = 0; % i'm using gray so it's easy to see
end
end
end
%imshow(img)
%filename = '181.png';
%img = imread(filename);
%img = im2gray(img); % need to work on the right image
% use the actual image dimensions
[nrows,ncols,~] = size(img);
for row = 1:nrows
for col = 1:ncols
% image origin is NW corner, so a line which points from SW to NE
% actually has negative slope!
if row < (0.77*col - 238.31)
img(row,col) = 0; % i'm using gray so it's easy to see
end
end
end
% New and corrected images aer writtedn under different file names, e.g.
% NEW1.png from 181.png, NEW2.png from 182.png, NEW3.png from 183.png
FName = strcat(['NEW', num2str(k), '.png']);
imshow(img)
imwrite(img, FName) ;
end
0 个评论
采纳的回答
MarKf
2023-2-7
COuld the problem (just a first glance) be here?
myFiles = dir(fullfile(myDir,'*.png')); %gets all png files in struct
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
%[imData, Fs] = imread(fullFileName);
% FName= myFiles.name; <----- why this line anyway?
FName= fullFileName;
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!