Clear Filters
Clear Filters

Decreasing graylevels of image using certain interval

2 views (last 30 days)
Hi,
How can i decrease the 255 gray level of image to 17 graylevels such that
-7 to +7 considered as gray level "0"
8 to 23 as "16"
24 to 39 as "32" and so on.. upto to 255.
pls help, thanks in advance...

Answers (2)

mark
mark on 28 Nov 2013
Edited: mark on 28 Nov 2013
I'd actually be interested in this too as I am currently using imagesc(X) for plotting stuff.
I found that if you go to the figure editor and right click on the colorbar, you can manually adjust it by scrolling on the bar. But, as with anything you edit post-process you need to do it every time.

Image Analyst
Image Analyst on 28 Nov 2013
Try this:
lut(1:8) = 0;
lut(8:23) = 16;
lut(24:39) = 32;
% and so on....
% To convert
outImage = intlut(inputImage, lut);
  4 Comments
Image Analyst
Image Analyst on 30 Nov 2013
It's in the Image Processing Toolbox. Do you have that? If you don't you can do it manually with one or more for loops.
Image Analyst
Image Analyst on 30 Nov 2013
You had mistakes in your code. LUT wasn't uint8 and didn't have 256 elements. Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in standard demo image;
grayImage = imread('cameraman.tif');
% Display the original gray scale image.
subplot(1, 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')
LUT(1:8) = 0;
LUT(8:23) = 16;
LUT(24:39) = 32;
LUT(40:55) = 48;
LUT(56:71) = 64;
LUT(72:87) = 80;
LUT(88:103) = 96;
LUT(104:119) = 112;
LUT(120:135) = 128;
LUT(136:151) = 144;
LUT(152:167) = 160;
LUT(168:183) = 176;
LUT(184:199) = 192;
LUT(200:215) = 208;
LUT(216:231) = 224;
LUT(232:247) = 240;
LUT(248:256) = 255;
LUT = uint8(LUT);
% To convert
quantizedImage = intlut(grayImage, LUT);
% Display the original gray scale image.
subplot(1, 2, 2);
imshow(quantizedImage, []);
title('Quantized Image', 'FontSize', fontSize);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!