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 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!