i have an ultrasound image i want to remove the labeles on the image by using y=mx+b line to convert the pixeles above the line to black.how can i do it?

2 ビュー (過去 30 日間)
filename = '181.png';
img= imread(filename);
gray = im2gray(img);
for i=1:434
for j=1:634
if(j < (0.77i+235))
img(i,j) = 255;
else
img(i,j)=0;
end
end
end
subplot(2,2,1), imshow(img),title('transformed image');

採用された回答

DGM
DGM 2023 年 2 月 2 日
There are a couple things going on here.
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 + 240)
img(row,col) = 128; % i'm using gray so it's easy to see
end
end
end
imshow(img)
This could also be done without the loops
filename = '181.png';
img = imread(filename);
img = im2gray(img); % need to work on the right image
[nrows,ncols,~] = size(img);
R = 1:nrows;
C = 1:ncols;
mask = R.' < (-0.77*C + 240);
img(mask) = 128;
imshow(img)
Alternatively, you could use a polygon mask to perform the selection. See drawpolygon() and createMask().

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by