필터 지우기
필터 지우기

convert the image to binary

조회 수: 7 (최근 30일)
Md
Md 2022년 9월 21일
댓글: Image Analyst 2022년 9월 21일
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
Walter Roberson
Walter Roberson 2022년 9월 21일
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 2022년 9월 21일
I need the image to be like this.

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

답변 (1개)

Walter Roberson
Walter Roberson 2022년 9월 21일
이동: Image Analyst 2022년 9월 21일
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
Md
Md 2022년 9월 21일
이동: Image Analyst 2022년 9월 21일
Thanks a lot!
Image Analyst
Image Analyst 2022년 9월 21일
@Md Please click the "Accept this answer" link to award @Walter Roberson reputation points. Thanks in advance. 🙂

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by