How do I invert a grayscale image and convert it to a binary image?

前端 未结 5 1384
栀梦
栀梦 2021-01-14 07:40

I want to create an image like this: \"alt From an image like this:

5条回答
  •  灰色年华
    2021-01-14 08:04

    It depends on what type your input matrix is.

    If it is a logical matrix you can simply use

    invImg = ~img;
    

    If you have scalar values in the range of 0 to n use

    invImg = n - img;
    

    Edit:

    If you want a black and white image try the following (perhaps you need to play with the level paramter):

    invImg = ~im2bw(img, 0.5);
    

提交回复
热议问题