Extract and show non zero pixels of a 2D image in MATLAB

조회 수: 14 (최근 30일)
sn at
sn at 2020년 5월 10일
답변: Image Analyst 2020년 5월 10일
Hello,
I have an image ima;
of size 256x96; I use find( ) to find the nonzero pixels' linear indices
indd=find(ima);
[row col]=ind2sub(size(ima),indd);
and I get two vectors,
row;
col;
How to show this new image, using imagesc ?
  댓글 수: 2
Matt J
Matt J 2020년 5월 10일
편집: Matt J 2020년 5월 10일
I use find( ) to find the nonzero pixels' linear indices
It is unnecessary to use ind2sub here. You can use find() to get the subscripts directly,
[row col]=find(ima);
How to show this new image
In what way are the row, col vectors to be considered an "image"?
sn at
sn at 2020년 5월 10일
What I think now is that the only way to be able to show this, is the same size as the original image, with all the zero pixels there.

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

답변 (2개)

Matt J
Matt J 2020년 5월 10일
편집: Matt J 2020년 5월 10일
The question seems very open ended. Perhaps as follows,
spy(ima)
  댓글 수: 1
sn at
sn at 2020년 5월 10일
thank you, this shows the nonzero pixels (which is the mask), but it does not have any output to be able to proceede with it.

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


Image Analyst
Image Analyst 2020년 5월 10일
Just tell us what you really want to do. If you just want to look at the image you'd use
imshow(ima);
That will show only non-zero pixels because the zero ones will show up as black.
If you want a list of them, you can use find() and that gives you a list of coordinates.
[rows, columns] = find(ima);
Now you have two vectors with the locations of the non-zero pixels. If you want them in an N-by-2 matrix of (x,y) coordinates, you can do
xy = [columns(:), rows(:)]
So that gives you basically everything you need. But we don't know what you really have in mind. You can't have an image show up where the zero pixels are like "holes" in the figure and you can see whatever is on your computer behind the figure as if the zero pixels were 100% transparent. And there is really no need for that anyway. So what do you really want to do? Do you just want to do some operation, like blurring or whatever, on the non-zero pixels? If you could do whatever you're thinking of, what would be the next step. You said you need an "output to be able to proceede with it.' Well, what does "proceede" mean to you? Do you want to measure intensity? Area of particles? What???

Community Treasure Hunt

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

Start Hunting!

Translated by