How can I make the Background of an image invisible? (R2018b)

조회 수: 1 (최근 30일)
Michael Dornseifer
Michael Dornseifer 2019년 9월 25일
답변: Mahesh Taparia 2019년 9월 30일
When I start to plot the image with imread, the image is plot with background. How can I set this background invisible or how I can delete the background?
I tried:
auto = imread('Auto.png', 'BackgroundColor','none') % this code not worked
and I also tried to cut (delete) the Background in other Programms.
Thank you for your help
  댓글 수: 4
Michael Dornseifer
Michael Dornseifer 2019년 9월 25일
@Johannes Fischer
The second option: I have a image and want to delete the background.
The Image is like the auto.png.
I only want the car, without the white background.
Johannes Fischer
Johannes Fischer 2019년 9월 25일
auto = imread('auto.png');
% create an alpha channel where the image is more transparent the brighter it is
% (only works with greyscale RG images, as im only using the red channel here)
alpha = 255 - auto(:, :, 1);
% make the lines a bit darker
auto(auto < 220) = 0;
% save image with alpha channel
imwrite(auto, 'auto_tp.png', 'Alpha', alpha)

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

답변 (1개)

Mahesh Taparia
Mahesh Taparia 2019년 9월 30일
Hi,
As per your image, it will be a two-class classification problem in an image. Since the image is a black and white and you want to extract the black pixels, it can be done by converting the image into gray color space and then using Otsu’s thresholding method by using 'multithresh' function to set proper threshold.
You can do so by executing the following lines of code:
auto = imread('auto.png');
Gray_img=rgb2gray(auto);
thres=multithresh(Gray_img);
Segmented_img= Gray_img <thres;
figure;imshow(Segmented_img)
imwrite(Segmented_img, 'auto_segmented.png')

Community Treasure Hunt

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

Start Hunting!

Translated by