Azzera filtri
Azzera filtri

convert the image to binary

7 visualizzazioni (ultimi 30 giorni)
Md
Md il 21 Set 2022
Commentato: Image Analyst il 21 Set 2022
I need to convert the first image to the second image. I posted about this before but the answers didn't help. One of my classmate suggested me to do this (he said that repeat bwareopen and medfilt2 a few time at the end, no specific number), but it didn't help:
RGB=imread("center.jpg");
a=medfilt3(RGB);
b=rgb2gray(a);
c=medfilt2(b);
d=imbinarize(c);
e=medfilt2(d);
imshow(e);
f=bwareaopen(e,1);
g=medfilt2(f);
h=bwareaopen(g,1);
i=medfilt2(h);
imshow(i);
j=bwareaopen(i,1);
k=medfilt2(j);
l=bwareaopen(k,1);
m=medfilt2(l);
Can I get any suggestions? Thank you!
  2 Commenti
Walter Roberson
Walter Roberson il 21 Set 2022
I need to convert this image to a clear binary image
Your code already converts to a "clear binary image" -- at least at least as much as you have defined "clear". Which is to say that since you did not indicate how "clear" is to be determined, any binary image satisfies the requirement.
Md
Md il 21 Set 2022
I need the image to be like this.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 21 Set 2022
Spostato: Image Analyst il 21 Set 2022
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1131025/image.jpeg';
RGB = imread(filename);
BW = all(RGB<64, 3);
imshow(BW)
center_only = bwareafilt(BW, 1);
imshow(center_only)
center_select = RGB .* uint8(center_only(:,:,[1 1 1]));
imshow(center_select)
That last image does not look like much, but it is the RGB of only the center line, with everything else set to 0. Maybe if we try
center_select2 = imcomplement(RGB) .* uint8(center_only(:,:,[1 1 1]));
imshow(center_select2)
This is an RGB image in "reverse color" in the center. Because the center that you are interested in happens to be dark.
Your target image has grayscale end-caps, but your source image has no end-caps. This last image, center_select2 would pull out grayscale if it meaningfully existed there.
  2 Commenti
Md
Md il 21 Set 2022
Spostato: Image Analyst il 21 Set 2022
Thanks a lot!
Image Analyst
Image Analyst il 21 Set 2022
@Md Please click the "Accept this answer" link to award @Walter Roberson reputation points. Thanks in advance. 🙂

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by