Can't view binary image

조회 수: 6 (최근 30일)
Mesho
Mesho 2023년 4월 14일
댓글: Image Analyst 2023년 4월 17일
Dear all, I couldn't view the binary image after runing this code
fab_img = imread('fabric.png');
Img = rgb2gray(fab_img);
BW1 = edge(Img,'sobel');
figure (500)
fig500 = gcf;
ax2 = subplot(1,1,1, 'Parent', fig500);
image(ax2, (BW1));
Any idea how to solve it without using imshow function?
Meshoo

채택된 답변

Image Analyst
Image Analyst 2023년 4월 14일
I would use imshow also. But if you insist on using image you can do it if you multiply the logical matrix by 255:
fab_img = imread('fabric.png');
Img = rgb2gray(fab_img);
BW1 = edge(Img,'sobel');
image(255 * BW1);
  댓글 수: 2
Mesho
Mesho 2023년 4월 17일
Thank you Image Analyst. I want a solution to the 'image' function properties such that it can show a binary image (not by changing my binary image to another a color or gray image).
Image Analyst
Image Analyst 2023년 4월 17일
Sorry we can't help you. We offered solutions and for some baffling reason you rejected all of them. "The idea here is not to use imshow function."
fab_img = imread('fabric.png');
subplot(2, 2, 1);
imshow(fab_img);
Img = rgb2gray(fab_img);
BW1 = edge(Img,'sobel');
% Option 1
subplot(2, 2, 2);
imshow(BW1);
% Option 2
subplot(2, 2, 3);
image(255 * BW1);
% Option 3 leave as binary but must convert to 3-D RGB image
subplot(2, 2, 4);
image(cat(3, BW1, BW1, BW1));
The display is just for your viewing pleasure. It doesn't have anything to do with the analysis of the image. I don't know how the image is displayed is of such great concern to you. Just pick one and go with it.

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

추가 답변 (1개)

Praveen Reddy
Praveen Reddy 2023년 4월 14일
편집: Praveen Reddy 2023년 4월 14일
Hi Mustafa,
I understand that you want to display binary image in a figure. You can use "imshow" method to display binary image.Refer to the following modified code.
fab_img = imread('fabric.png');
Img = rgb2gray(fab_img);
BW1 = edge(Img,'sobel');
figure (500)
fig500 = gcf;
ax2 = subplot(1,1,1, 'Parent', fig500);
imshow(BW1);
To know more about "imshow" method, please refer to the following MATLAB documentation
  댓글 수: 1
Mesho
Mesho 2023년 4월 14일
Thank you Praveen. The idea here is not to use imshow function.
I need to call the figure. The above code works for rgb images but not for binary images and I wonder if there is any way to solve it.

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by