Reset value of pixels of side of imagine line.

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2016-10-31
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 个评论
Walter Roberson
Walter Roberson 2016-10-31
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by