Azzera filtri
Azzera filtri

Reset value of pixels of side of imagine line.

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Ott 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 Commenti
Walter Roberson
Walter Roberson il 31 Ott 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by