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

1 view (last 30 days)
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 Comments
Michael Dornseifer
Michael Dornseifer on 25 Sep 2019
@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 on 25 Sep 2019
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)

Sign in to comment.

Answers (1)

Mahesh Taparia
Mahesh Taparia on 30 Sep 2019
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!