Filter löschen
Filter löschen

convert the image to binary

7 Ansichten (letzte 30 Tage)
Md
Md am 21 Sep. 2022
Kommentiert: Image Analyst am 21 Sep. 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 Kommentare
Walter Roberson
Walter Roberson am 21 Sep. 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 am 21 Sep. 2022
I need the image to be like this.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Sep. 2022
Verschoben: Image Analyst am 21 Sep. 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 Kommentare
Md
Md am 21 Sep. 2022
Verschoben: Image Analyst am 21 Sep. 2022
Thanks a lot!
Image Analyst
Image Analyst am 21 Sep. 2022
@Md Please click the "Accept this answer" link to award @Walter Roberson reputation points. Thanks in advance. 🙂

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by