Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe02.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Can nobody help me???
References: <gfc8tj$4mb$1@aioe.org> <gfc9ou$33r$1@fred.mathworks.com> <2002cdb8-6508-4455-a065-825124e142c0@q26g2000prq.googlegroups.com> <gfh642$6gh$1@aioe.org>
In-Reply-To: <gfh642$6gh$1@aioe.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 40
Message-ID: <WNjTk.352$VN1.280@newsfe02.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe02.iad 1226688758 24.79.146.116 (Fri, 14 Nov 2008 18:52:38 UTC)
NNTP-Posting-Date: Fri, 14 Nov 2008 18:52:38 UTC
Date: Fri, 14 Nov 2008 12:52:59 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:500880


Vicky wrote:
 
> In each pixel is an rgb value like (8, 8, 8) or (12, 12, 12). But I want 
> that in each pixel is the label like 1, 2,...8,...12,...
> That means that in each pixel should be a single scalar value and not 
> the color.

I'm not clear on what you are asking. With your repetitions of the fact that you
want each pixel to be the "label" and not the colour, then it sounds like what you
want to produce is an image in which everywhere that the original image would
have been labeled with 1, the new image would show the -character- 1, and so
on -- an image composed of text drawn in to the appropriate places.

If your goal was just to store binary data corresponding to the label, then
it is not clear why you would bother to store it in an image file, but there is
some hidden Very Good Reason For This, then create a new matrix which is
NewImageG = uint16(LabelMatrix);
and write that out using 'png' or 'ppm' or 'jpg' format. You may need
to use the jpg options
'Bitdepth', 16, 'Mode', 'lossless'


If you -must- use BMP for your purposes, then if L is your label matrix:

L16 = uint16(L);
Lrgb = cat(3,zeros(size(L16),'uint8'),uint8(bitshift(L16,-8)),uint8(bitand(L16,uint16(255))));
imwrite(Lrgb, 'FileName.bmp');

and to read the values back in:

Lrgb = imread('FileName.bmp');
L = bitor(bitshift(uint16(Lrgb(:,:,2)),8),uint16(Lrgb(:,:,3)));

This code would need some minor adjustment if you have more than 65535 labels.

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?