Effacer les filtres
Effacer les filtres

Reset value of pixels of side of imagine line.

1 vue (au cours des 30 derniers jours)
Amin Ghasemi
Amin Ghasemi le 31 Oct 2016
Commenté : Amin Ghasemi le 31 Oct 2016
Hi.
I have two known coordinates in a colorful image. I wanna reset value of pixels in one side of the line. for more clarifying, I've shown my process in following picture.
any help would be appreciated.

Réponse acceptée

Walter Roberson
Walter Roberson le 31 Oct 2016
You can use the coordinates to get slope and intercept of the dividing line. From there you could work row by row zeroing out the pixels to the right of where the slope meets the row; or you could vectorize it all using ndgrid or meshgrid on indexing matrices...
[Y, X] = ndgrid(1:size(YourIm,1), 1:size(YourIm,2));
NewIm = YourIm;
NewIm(repmat(Y < m*X+b,1,1,3)) = 0; %the repmat duplicates the 2D mask into all bit planes
If you have a sufficiently new MATLAB, R2016b or later, you can do it without the ndgrid:
Y = (1:size(YourIm,1)).'; %column vector
X = 1 : size(YourIm,2)); %row vector
NewIm( repmat(Y < m*X+b, 1, 1, 3) ) = 0; %the repmat duplicates the 2D mask into all bit planes
  3 commentaires
Walter Roberson
Walter Roberson le 31 Oct 2016
ndgrid() is the full vectorized method.
You can use calculations such as
NewIm = YourIm;
for X = 1 : size(YourIm,2))
Y = m*X + b;
NewIm(ceil(Y):end, X, :) = 0;
end
but that requires a loop. If you want to test each location in the image "simultaneously" then you need to create grids of indices.
Amin Ghasemi
Amin Ghasemi le 31 Oct 2016
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by