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

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

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

5条回答
  •  失恋的感觉
    2021-01-14 07:52

    I had some trouble processing the second image you posted above. Since it's in JPEG format, the image compression seems to have made the lines and text fuzzy, and that complicates thresholding it in the way that you want.

    I instead went back to the indexed-color GIF image you posted on the previous related question, converted it to grayscale (using the function IND2GRAY from the Image Processing Toolbox), then converted that to a reversed black and white image to match the format of the first image you posted above. Here's the code I used:

    [X,map] = imread('original_chart.gif');  %# Load the indexed color image
    img = ind2gray(X,map);                   %# Convert the image to grayscale
    reversedImage = img < max(img(:));       %# Convert to reversed black and white
    

    And here's what reversedImage looks like:

    alt text

提交回复
热议问题