Can I convert one image in grayscale to monochrome?

13 views (last 30 days)
Hello friends, I would know if there is chance to convert an grayscale image to monochrome

Accepted Answer

Image Analyst
Image Analyst on 8 Jun 2013
A grayscale image is monochrome. There is nothing to do. There are no colors. Just look at the web site for any camera manufacturer out there, such as this really excellent camera from Lumenera: http://www.lumenera.com/products/industrial-cameras/lw11059.php. Gray scale images are monochrome, according to accepted and widely used industry terminology. (Of course a thresholded/binary image like Walter showed is also monochrome because it has no color, though I'd call them binary or logical since they don't have any grays in them other than pure black or pure white.)
  6 Comments
Image Analyst
Image Analyst on 18 Mar 2022
@Manuel that link doesn't work. Here is my code again with the input image attached and the output screenshot.
%============================================================================================================================================
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
markerSize = 4;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'greens.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Convert to grayscale
grayImage = rgb2gray(rgbImage);
% Display the image.
subplot(2, 2, 2);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize);
% Get an estimate of the background.
windowSize = 41;
backgroundImage = imfilter(double(grayImage), ones(windowSize)/windowSize^2);
% Display the image.
subplot(2, 2, 3);
imshow(backgroundImage, []);
title('Background Estimate', 'FontSize', fontSize);
% Subtract the background from the gray image.
backgroundSubtractedImage = double(grayImage) - backgroundImage;
% Display the image.
subplot(2, 2, 4);
imshow(backgroundSubtractedImage, []);
title('Background Subtracted Image', 'FontSize', fontSize);
Like I said, it's no good but it's what you asked for originally (before you deleted your original question).

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 8 Jun 2013
monochrome = (grayimage > some_threshold)
and see graythresh()
  4 Comments
Manuel
Manuel on 8 Jun 2013
I will explain my problem, I have to do a segmentation process, for this situation I have to do monochromatic representation of the original color image who is normalised by subtract an estimate of background, witch is the result of a filtering operation with a large arithmetic mean kernel.
Walter Roberson
Walter Roberson on 8 Jun 2013
convert the original color image to double precision; convert the estimated background to double precision. Subtract to get the normalized version.
However, you cannot convert the normalized version to monochromatic by the usual calculation of luminance, as the calculation of luminance assumes that all the values are positive. You could calculate something, but it would not have any physical interpretation.
If you want to calculate the "something", then have a look at the documentation for rgb2gray() to find the formula that is used to convert RGB to luminance, and apply that formula to the normalized version that was calculated. You will get luminance-like values, but some of them will be negative and Science has yet to find a meaning for negative light. (How fast does negative light travel? -1*c ? Or should negative luminance be matched to tachyons ?)

Sign in to comment.


DGM
DGM on 18 Mar 2022
One doesn't normalize data by subtraction. The process as described is common except for that one misunderstanding:
A = imread('printedtext.png');
A = im2double(A);
imshow(A)
bgest = imgaussfilt(A,30);
B = mat2gray(A./bgest); % use division
imshow(B)
This is essentially a local normalization process. To bring the image back into standard data range, I here chose to normalize the result using mat2gray().
An alternative would be to use imflatfield(). This would be essentially identical, except the result would be scaled by the mean of the background estimate instead of being normalized as with mat2gray(). The result is darker, but otherwise identical.
C = imflatfield(A,30);
imshow(C)
  1 Comment
Image Analyst
Image Analyst on 18 Mar 2022
I didn't know of the imflatfield() function. Thanks. I'll have to look into it.
You're right to use background division. Most people do background subtraction and that is not right except for a few cases like radiography and fluorescence.
As a final note I can see that my original answer up there has nothing at all to do with the (now) original post so it's very obvious that the original poster changed the post DRASTICALLY. I'll see if I can at least add some image and screenshot so that my answer makes sense by itself. I always attach the image and resulting screenshot so I'm not sure how they got removed. I often attach a text file with the author's post if it's the authors very first post since with first-time authors there is a very high probability they will obliterate their original post (like in this thread). The link @Manuel gave in a comment is also now broken.
Finally, I offer another algorithm to do document correction. It's meant to restore text, writing, or line diagrams on historical documents where the page has undergone color and brightness degradations.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!