Effacer les filtres
Effacer les filtres

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?

1 vue (au cours des 30 derniers jours)
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');

Réponse acceptée

DGM
DGM le 2 Fév 2023
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().

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by