Filter löschen
Filter löschen

Reset value of pixels of side of imagine line.

1 Ansicht (letzte 30 Tage)
Amin Ghasemi
Amin Ghasemi am 31 Okt. 2016
Kommentiert: Amin Ghasemi am 31 Okt. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Okt. 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 Kommentare
Walter Roberson
Walter Roberson am 31 Okt. 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 am 31 Okt. 2016
thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by