How to remove background color from an image?

조회 수: 7 (최근 30일)
Amanda Capacchione
Amanda Capacchione 2021년 10월 31일
댓글: Sulaymon Eshkabilov 2021년 11월 1일
Hello,
I'm fairly inexperienced with Matlab - and coding in general - but I'm trying to use it for a project. The image I've attached is a slice from a material structure. It shows the crystal structure in the z-plane.
I'm trying to remove the background (black) and turn the white lines into points, or line segments, that can be uploaded into Solidworks since I'm trying to use the lines/points to recreate a crystal path into a 3D model.
Any help would be appreciated, whether it be examples or references that can help me figure out what I'm trying to do.
Thanks to anyone who can help me out!
  댓글 수: 2
Image Analyst
Image Analyst 2021년 10월 31일
Not sure what you want/need. Do you just want the row, column location of all the white pixels?
Amanda Capacchione
Amanda Capacchione 2021년 10월 31일
@Image Analyst My apologies if my question wasn't very clear, but yes that would be what I'm looking for! Would I be able to do that using the image processing toolbox?

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 31일
D = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/784688/image.png');
subplot(211)
imshow(D)
I = D;
M= rgb2gray(I);
Mn = M==0;
M1 = (Mn*1); M1 = cat(3, M1, M1, M1);
subplot(212)
imshow(M1)
% The coodinates can be found as Image Analyst suggested:
[rows, cols] = find(M); % Coordinates of Gray Image
% Note that they need to be in a reverse order to match with the original IMAGE:
plot(cols, rows, 'k.', 'MarkerSize', 10)
axis ij; axis tight
  댓글 수: 2
Amanda Capacchione
Amanda Capacchione 2021년 10월 31일
This is great and will provide me with more than enough foundation to tinker around with. Thank you so much for your help! :)
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 1일
Most Welcome! Glad to help. All the best :)

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

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 31일
D = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/784688/image.png');
subplot(211)
imshow(D)
I = D;
M= rgb2gray(I);
Mn = M==0;
M1 = (Mn*1); M1 = cat(3, M1, M1, M1);
subplot(212)
imshow(M1)
  댓글 수: 2
Amanda Capacchione
Amanda Capacchione 2021년 10월 31일
Thank you, Sulaymon, for this. This accomplishes part of what I was aiming for.
I'm trying to take what you've provided and somehow recreate the second plot and map the black lines into an array of points. I'm not sure if that would be possible to do. But, it'll almost be like vectorizing the image, except with a series of points rather than lines. So, looking at the bottom figure you created and taking the black lines of the image, and somehow transforming it into a network of points.
Again, thank you for your help.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 31일
편집: Sulaymon Eshkabilov 2021년 10월 31일
ok

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


Image Analyst
Image Analyst 2021년 10월 31일
If you have a binary image with zeros and non-zeros, you can get the coordinates of all the white points like this:
[rows, columns] = find(yourImage);
If you want to plot them you can do
plot(columns, rows, '.', 'k', 'MarkerSize', 10);
axis ij;
  댓글 수: 1
Amanda Capacchione
Amanda Capacchione 2021년 10월 31일
Thank you as well @Image Analyst, you managed to also help me figure out how to understand my original problem!

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

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by