How to remove background color from an image?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Amanda Capacchione
il 31 Ott 2021
Commentato: Sulaymon Eshkabilov
il 1 Nov 2021
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 Commenti
Image Analyst
il 31 Ott 2021
Not sure what you want/need. Do you just want the row, column location of all the white pixels?
Risposta accettata
Sulaymon Eshkabilov
il 31 Ott 2021
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 Commenti
Più risposte (2)
Sulaymon Eshkabilov
il 31 Ott 2021
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 Commenti
Image Analyst
il 31 Ott 2021
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;
Vedere anche
Categorie
Scopri di più su Modify Image Colors in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!