How to feature extract from an image with black background(without taking the black background in consideration)?

조회 수: 1 (최근 30일)
I was scrolling through some answers of the same issue and got the following
C = num2cell(YourImage);
C(~YourImage) = {{}};
This will give you a cell array in which there are empty cells ("nothing") where the background was, and cells containing [1] where the foreground was.And
imagesc(YourImage, 'AlphaData', YourImage)
colormap(gray)
set(gca, 'color', 'none')
to set the Region of interest visible,i did try it myself and didn't get a result,What am i doing wrong and the correct way to use this code.

채택된 답변

Image Analyst
Image Analyst 2017년 6월 16일
Looks weird. Very, very weird. I'd say what you're doing wrong is using cells in the first place. I don't see any reason for that. Why put each pixel into a cell? And then make the cells empty where the image is zero? And it's not going to put a 1 in cells with foreground. It's going to have the original gray levels in the cells. I mean, you could simply do the same thing that you say you want (0=background of 0, and 1 = foreground of non-zero) much better and with far, far less memory usage simply by saying
C = (YourImage ~= 0).
Post your image and say what feature in it that you're trying to measure.
  댓글 수: 9
Elias Unk
Elias Unk 2017년 6월 17일
I did try the code again to make sure i didn't make any wrong step and for the following code
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
mask = ~(redChannel == 0 & greenChannel == 0 & blueChannel == 0);
I ended up with the same result,doesn't make sense to me either but try it out yourself.
Image Analyst
Image Analyst 2017년 6월 17일
The two binary images you posted don't look anything like the masked RGB images you posted. The only way my code would look like the larger bottom binary image you posted is if your image is heavily corrupted with JPG artifacts. In that case you may have to check not for exact zero, but some small value, like 9 or something;
mask = ~(redChannel <= 9 & greenChannel <= 9 & blueChannel <= 9);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by