フィルターのクリア

Reset value of pixels of side of imagine line.

1 回表示 (過去 30 日間)
Amin Ghasemi
Amin Ghasemi 2016 年 10 月 31 日
コメント済み: Amin Ghasemi 2016 年 10 月 31 日
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.
Amin Ghasemi
Amin Ghasemi 2016 年 10 月 31 日
thanks

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by