Delete a specific pixels of an image

조회 수: 4 (최근 30일)
David Zapata
David Zapata 2017년 10월 7일
댓글: David Zapata 2017년 10월 9일
I need to delete a specific pixel of an image, I have its coordinates, x and y, but I do not know how to delete only that one pixel.
My code is this:
B6 = imread('B6.TIF');
imshow(B6);
[x, y] = ginput(1);

채택된 답변

Nada Kamona
Nada Kamona 2017년 10월 8일
Hi David,
I'm not sure what you mean by delete just that pixel. So I'm assuming you only want to set that pixel at value equal to zero or NaN, while keeping the image at the same size. If this is what you want, and assuming x and y are the location of the pixel, then you can simply do the following:
B6(x,y) = 0;
% Or ...
B6(x,y) = NaN;
Please note that if x and y are arrays of coordinates, the above code still works. It will set all the points to zeros/NaNs.
Hope this helps!
  댓글 수: 2
Image Analyst
Image Analyst 2017년 10월 8일
Note: for a uint8 or uint16 image, setting to nan will set it to 0, not nan. And you reversed x and y. You'd need to have
B(ceil(y), ceil(x)) = 0; % Round and put y first, NOT x.
David Zapata
David Zapata 2017년 10월 9일
thanks for your help

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Community Treasure Hunt

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

Start Hunting!

Translated by