hi I want to put a floating point number(e.g. 2.4598) in one pixel of image. is it possible? how? thanks
MATLAB: Floating point number in one pixel of image
image processingImage Processing Toolbox
Related Solutions
I see no reason why imquantize() won't work. Please show your code that demonstrates why imquantize() fails.
Alternatively you can use mat2gray followed by multiplication, as this demo shows:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;format compact;fontSize = 15;% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');if button == 1 baseFileName = 'cameraman.tif';elseif button == 2 baseFileName = 'moon.tif';elseif button == 3 baseFileName = 'eight.tif';elseif button == 4 baseFileName = 'coins.png';else baseFileName = 'pout.tif';end% Read in a standard MATLAB gray scale demo image.folder = fullfile(matlabroot, '\toolbox\images\imdemos');baseFileName = baseFileName;% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % File doesn't exist -- 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 in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendgrayImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);% Display the original gray scale image.
subplot(2, 2, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') % Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);subplot(2, 2, 2); bar(pixelCount);grid on;title('Histogram of original image', 'FontSize', fontSize);xlim([0 grayLevels(end)]); % Scale x axis manually.
% Quantize
numberOfGrayLevels = 4;quantizedImage = uint8(mat2gray(grayImage) * (numberOfGrayLevels-1));% Display the original gray scale image.subplot(2, 2, 3);imshow(quantizedImage, []);caption = sprintf('Image quantized into %d gray levels', numberOfGrayLevels);title(caption, 'FontSize', fontSize);% Enlarge figure to full screen.set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Give a name to the title bar.set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') % Let's compute and display the histogram.[pixelCount grayLevels] = imhist(quantizedImage);subplot(2, 2, 4); bar(pixelCount);grid on;caption = sprintf('Histogram of image quantized into %d gray levels', numberOfGrayLevels);title(caption, 'FontSize', fontSize);lastGL = find(pixelCount>0, 1, 'last');xlim([0 lastGL+1]); % Scale x axis manually.
E.g.,
>> X = 1X = 1>> Y = X + eps(X)Y = 1.0000>> Z = X - eps(X)Z = 1.0000>> num2strexact(X)ans =1>> num2strexact(Y)ans =1.0000000000000002220446049250313080847263336181640625>> num2strexact(Z)ans =0.9999999999999997779553950749686919152736663818359375
X, Y, and Z all print as 1 or 1.0000, but they are in fact different. You can find num2strexact here:
href=""<http://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str</a>>
Best Answer