Re: Converting 256 level image to a 16 level image
- From: Dev <gunadp@xxxxxxxxx>
- Date: Sun, 8 Jun 2008 18:19:43 -0700 (PDT)
On Jun 9, 10:29 am, ImageAnalyst <imageanal...@xxxxxxxxxxxxxx> wrote:
On Jun 8, 7:40 pm, gun...@xxxxxxxxx wrote:
On Jun 7, 4:21 am, "Roger Stafford"
<ellieandrogerxy...@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"Roger Stafford" <ellieandrogerxy...@xxxxxxxxxxxxxxxxxxxxxx> wrote in
message <g2bdai$pu...@xxxxxxxxxxxxxxxxxx>...> Good point, Walter. If it is to be some kind of mapping, one can define a
15-element monotonically increasing mapping vector g with g(i) being the
smallest value in the range 0:255 which is to map into i and if the value is
less than g(1), it maps into 0. Let x be an array of values, each in the range
from 0 to 255. Then do this binary search table lookup:
y = repmat(8,size(x));
for k = [4,2,1,1/2]
y = y + (2*(x>=reshape(g(y),size(x)))-1)*k;
end
y = y - 1/2;
Then y would be the mapping of array x into the range 0:15 in accordance
with the mapping defined by g.
-----------
To avoid two of the reshapes, I should probably have written the binary
search above as follows. First, make sure g is defined as a column vector.
x2 = x(:);
y = repmat(8,size(x2));
for k = [4,2,1,1/2]
y = y + (2*(x2>=g(y))-1)*k;
end
y = reshape(y-1/2,size(x));
Roger Stafford
Hi Roger and walter
Thanks for the replies. As I am new to this field I am having problems
in showing the image once I scale to a different level. For example
if I run the following code,
A = imread('C:\TestData\lena.tif');
D = floor(A/16);
figure; imshow(D);
A has values upto 255 and D upto 16, but the image shown is a blank
(black) image. Is there anything else I have to do? Your help is
greatly appreciated
thanks,
Dev- Hide quoted text -
- Show quoted text -
-------------------------------------------------------------------
Dev:
It by default displays the range 0-255 since you probably have a uint8
image. 16 gray levels is so dark that it's virtually black. Use []
as the second argument in imshow() to get it to display your 16 gray
levels with the full range of the display.
imshow(D, []);
By the way, it's a good idea to use descriptive variable names in case
someone else ever has to support your code. For example
originalImage = imread('C:\TestData\lena.tif');
reducedGrayLevelImage = floor(originalImage / 16);
figure;
imshow(reducedGrayLevelImage , []);
Regards,
ImageAnalyst
P.S. If you see equals3D instead of the equals sign, it's because
you're using a newsreader that doesn't understand the "quoted
printable" standard for messages (like the MATLAB web-based newsread.)- Hide quoted text -
- Show quoted text -
Thanks, it works.
.
- References:
- Converting 256 level image to a 16 level image
- From: gunadp
- Re: Converting 256 level image to a 16 level image
- From: Roger Stafford
- Re: Converting 256 level image to a 16 level image
- From: Walter Roberson
- Re: Converting 256 level image to a 16 level image
- From: Roger Stafford
- Re: Converting 256 level image to a 16 level image
- From: Roger Stafford
- Re: Converting 256 level image to a 16 level image
- From: gunadp
- Re: Converting 256 level image to a 16 level image
- From: ImageAnalyst
- Converting 256 level image to a 16 level image
- Prev by Date: Duration of different arrays
- Next by Date: Re: Problem removing border from figure
- Previous by thread: Re: Converting 256 level image to a 16 level image
- Next by thread: Re: Converting 256 level image to a 16 level image
- Index(es):
Relevant Pages
|