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!