Thread Subject: Can nobody help me???

Subject: Can nobody help me???

From: Vicky

Date: 11 Nov, 2008 15:38:20

Message: 1 of 9

Hallo there,

this is my code:

image1 = imread('image1.bmp');
image1 = im2bw(image1);
M = bwlabel(image1, 8);
imwrite(M, 'myImage.bmp');

How can I save an image (bmp), so that in each pixel is the element of
the matrice M?

If I save the matrice M with the command "imwrite" in each pixel of the
myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
label (element) of the matrice M.

How can I realize it?

Please I need help!!!

Best regards,
Vicky

Subject: Can nobody help me???

From: David

Date: 11 Nov, 2008 15:53:02

Message: 2 of 9

Vicky <bonsai19@gmx.de> wrote in message <gfc8tj$4mb$1@aioe.org>...
> Hallo there,
>
> this is my code:
>
> image1 = imread('image1.bmp');
> image1 = im2bw(image1);
> M = bwlabel(image1, 8);
> imwrite(M, 'myImage.bmp');
>
> How can I save an image (bmp), so that in each pixel is the element of
> the matrice M?
>
> If I save the matrice M with the command "imwrite" in each pixel of the
> myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
> label (element) of the matrice M.
>
> How can I realize it?
>
> Please I need help!!!
>
> Best regards,
> Vicky

well, a bmp file is normally a simple rgb format. read the help for imwrite and see if one of the other formats may be better for what you want. or you may just want to save M to something else, like a mat file instead of as an image.

Subject: Can nobody help me???

From: Adam Chapman

Date: 11 Nov, 2008 15:57:41

Message: 3 of 9

On Nov 11, 3:53=A0pm, "David" <d...@bigcompany.com> wrote:
> Vicky <bonsa...@gmx.de> wrote in message <gfc8tj$4m...@aioe.org>...
> > Hallo there,
>
> > this is my code:
>
> > image1 =3D imread('image1.bmp');
> > image1 =3D im2bw(image1);
> > M =3D bwlabel(image1, 8);
> > imwrite(M, 'myImage.bmp');
>
> > How can I save an image (bmp), so that in each pixel is the element of
> > the matrice M?
>
> > If I save the matrice M with the command "imwrite" in each pixel of the
> > myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
> > label (element) of the matrice M.
>
> > How can I realize it?
>
> > Please I need help!!!
>
> > Best regards,
> > Vicky
>
> well, a bmp file is normally a simple rgb format. =A0read the help for im=
write and see if one of the other formats may be better for what you want. =
=A0or you may just want to save M to something else, like a mat file instea=
d of as an image.- Hide quoted text -
>
> - Show quoted text -

Use the "save" command, and save the variable M in a .mat file

Subject: Can nobody help me???

From: Richard Brown

Date: 11 Nov, 2008 21:19:13

Message: 4 of 9

On Nov 12, 4:38=A0am, Vicky <bonsa...@gmx.de> wrote:
> Hallo there,
>
> this is my code:
>
> image1 =3D imread('image1.bmp');
> image1 =3D im2bw(image1);
> M =3D bwlabel(image1, 8);
> imwrite(M, 'myImage.bmp');
>
> How can I save an image (bmp), so that in each pixel is the element of
> the matrice M?
>
> If I save the matrice M with the command "imwrite" in each pixel of the
> myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
> label (element) of the matrice M.
>
> How can I realize it?
>
> Please I need help!!!
>
> Best regards,
> Vicky

Hi Vicky

bwlabel creates a matrix of doubles (which imwrite assumes are between
0 and 1). If you convert it to an unsigned integer format, e.g

M =3D uint8(M) % (or uint16, uint32, etc)

then saving to a bmp will probably give you what you want

cheers,

Richard

Subject: Can nobody help me???

From: ImageAnalyst

Date: 12 Nov, 2008 02:02:02

Message: 5 of 9

On Nov 11, 10:53=A0am, "David" <d...@bigcompany.com> wrote:
> Vicky <bonsa...@gmx.de> wrote in message <gfc8tj$4m...@aioe.org>...
> > Hallo there,
>
> > this is my code:
>
> > image1 =3D imread('image1.bmp');
> > image1 =3D im2bw(image1);
> > M =3D bwlabel(image1, 8);
> > imwrite(M, 'myImage.bmp');
>
> > How can I save an image (bmp), so that in each pixel is the element of
> > the matrice M?
>
> > If I save the matrice M with the command "imwrite" in each pixel of the
> > myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
> > label (element) of the matrice M.
>
> > How can I realize it?
>
> > Please I need help!!!
>
> > Best regards,
> > Vicky
>
> well, a bmp file is normally a simple rgb format. =A0read the help for im=
write and see if one of the other formats may be better for what you want. =
=A0or you may just want to save M to something else, like a mat file instea=
d of as an image.- Hide quoted text -
>
> - Show quoted text -

---------------------------------------------
Correct. Save in Tiff format instead. It can take monochrome.
Regards,
ImageAnalyst

Subject: Can nobody help me???

From: Vicky

Date: 13 Nov, 2008 12:21:12

Message: 6 of 9

Hi ImageAnalyst,

Thank you for your answer.
I saved it in tiff format but I still get rgb-values.

This is my code:

image1 = imread('org_001.bmp');
image1 = im2bw(image1);
L1 = bwlabel(image1, 8);
imwrite(L1/255, 'image.tiff')

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.

What I'm doing wrong when saving?

Then I have a question. In my original rgb images are more than 256
colors. Is it still possible to create a monochrome image, so that each
color get a seperate label?

Can you please help me again?

Best regards,
Vicky




ImageAnalyst schrieb:
> On Nov 11, 10:53 am, "David" <d...@bigcompany.com> wrote:
>> Vicky <bonsa...@gmx.de> wrote in message <gfc8tj$4m...@aioe.org>...
>>> Hallo there,
>>> this is my code:
>>> image1 = imread('image1.bmp');
>>> image1 = im2bw(image1);
>>> M = bwlabel(image1, 8);
>>> imwrite(M, 'myImage.bmp');
>>> How can I save an image (bmp), so that in each pixel is the element of
>>> the matrice M?
>>> If I save the matrice M with the command "imwrite" in each pixel of the
>>> myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
>>> label (element) of the matrice M.
>>> How can I realize it?
>>> Please I need help!!!
>>> Best regards,
>>> Vicky
>> well, a bmp file is normally a simple rgb format. read the help for imwrite and
>> see if one of the other formats may be better for what you want. or you may just
>> want to save M to something else, like a mat file instead of as an image.- Hide
>>quoted text -
>>
>> - Show quoted text -
>
> ---------------------------------------------
> Correct. Save in Tiff format instead. It can take monochrome.
> Regards,
> ImageAnalyst

Subject: Can nobody help me???

From: Walter Roberson

Date: 14 Nov, 2008 18:52:59

Message: 7 of 9

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)?

Subject: Can nobody help me???

From: Image Analyst

Date: 15 Nov, 2008 03:45:03

Message: 8 of 9

Vicky <bonsai19@gmx.de> wrote in message <gfh642$6gh$1@aioe.org>...
> Hi ImageAnalyst,
>
> Thank you for your answer.
> I saved it in tiff format but I still get rgb-values.
>
> This is my code:
>
> image1 = imread('org_001.bmp');
> image1 = im2bw(image1);
> L1 = bwlabel(image1, 8);
> imwrite(L1/255, 'image.tiff')
>
> 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.
>
> What I'm doing wrong when saving?
>
> Then I have a question. In my original rgb images are more than 256
> colors. Is it still possible to create a monochrome image, so that each
> color get a seperate label?
>
> Can you please help me again?
>
> Best regards,
> Vicky
>
>
>
>
> ImageAnalyst schrieb:
> > On Nov 11, 10:53 am, "David" <d...@bigcompany.com> wrote:
> >> Vicky <bonsa...@gmx.de> wrote in message <gfc8tj$4m...@aioe.org>...
> >>> Hallo there,
> >>> this is my code:
> >>> image1 = imread('image1.bmp');
> >>> image1 = im2bw(image1);
> >>> M = bwlabel(image1, 8);
> >>> imwrite(M, 'myImage.bmp');
> >>> How can I save an image (bmp), so that in each pixel is the element of
> >>> the matrice M?
> >>> If I save the matrice M with the command "imwrite" in each pixel of the
> >>> myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
> >>> label (element) of the matrice M.
> >>> How can I realize it?
> >>> Please I need help!!!
> >>> Best regards,
> >>> Vicky
> >> well, a bmp file is normally a simple rgb format. read the help for imwrite and
> >> see if one of the other formats may be better for what you want. or you may just
> >> want to save M to something else, like a mat file instead of as an image.- Hide
> >>quoted text -
> >>
> >> - Show quoted text -
> >
> > ---------------------------------------------
> > Correct. Save in Tiff format instead. It can take monochrome.
> > Regards,
> > ImageAnalyst
-------------------------------------------------------
OK, Vicky. Run this code that I've posted before that will find blobs and label and measure them. For you, I've adapted it to write out a tif image like you want, then i read it back in and display it with imtool so you can mouse around and inspect the values to verify that they are in fact the label values.
Regards,
ImageAnalyst

disp(' ');
disp('Running BlobsDemo.m...');
originalImage = imread('coins.png'); % Read in image
binaryImage = im2bw(originalImage, 0.4); % Threshold to binary

subplot(3,2,1); imagesc(originalImage); colormap(gray(256)); title('Original Image');
subplot(3,2,2); imagesc(binaryImage); colormap(gray(256)); title('Binary Image');

labeledImage = bwlabel(binaryImage, 8); % Label each blob so can do calc on it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels

% Save the labeled image as a tif image.
imwrite(uint16(labeledImage), 'tif_labels.tif');
tifimage = imread('tif_labels.tif');
imtool(tifimage, []); % Use imtool so she can inspect the values.

subplot(3,2,3); imagesc(labeledImage); title('Labeled Image');
subplot(3,2,4); imagesc(coloredLabels); title('Pseudo colored labels');

blobMeasurements = regionprops(labeledImage, 'all'); % Get all the blob properties.
numberOfBlobs = size(blobMeasurements, 1);

% bwboundaries returns a cell array, where each cell
% contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original
% grayscale image using the coordinates returned by bwboundaries.
subplot(3,2,5); imagesc(originalImage); title('Outlines');
hold on;
boundaries = bwboundaries(binaryImage);
for k = 1 : numberOfBlobs
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;

fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid\n');
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the mean of each blob. (R2008a has a better way where you can pass the original image
% directly into regionprops. The way below works for all versions including earlier versions.)
    thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of pixels in current blob.
    meanGL = mean(originalImage(thisBlobsPixels)); % Find mean intensity (in original image!)
blobArea = blobMeasurements(k).Area; % Get area.
blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
    fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL, blobArea, blobPerimeter, blobCentroid);
end
msgbox('Finished running BlobsDemo.m. Check out the figure window and the command window for the results.');

Subject: Can nobody help me???

From: Vicky

Date: 16 Nov, 2008 23:19:32

Message: 9 of 9

Hi ImageAnalyst,

thank you very much for your help and the code.

Best regards,
Vicky



ImageAnalyst schrieb:
> On Nov 11, 10:53 am, "David" <d...@bigcompany.com> wrote:
>> Vicky <bonsa...@gmx.de> wrote in message <gfc8tj$4m...@aioe.org>...
>>> Hallo there,
>>> this is my code:
>>> image1 = imread('image1.bmp');
>>> image1 = im2bw(image1);
>>> M = bwlabel(image1, 8);
>>> imwrite(M, 'myImage.bmp');
>>> How can I save an image (bmp), so that in each pixel is the element of
>>> the matrice M?
>>> If I save the matrice M with the command "imwrite" in each pixel of the
>>> myImage.bmp is an rgb-value. But I don't want a rgb-value, I want the
>>> label (element) of the matrice M.
>>> How can I realize it?
>>> Please I need help!!!
>>> Best regards,
>>> Vicky
>> well, a bmp file is normally a simple rgb format. read the help for imwrite and
>> see if one of the other formats may be better for what you want. or you may just
>> want to save M to something else, like a mat file instead of as an image.- Hide
>> quoted text -
>>
>> - Show quoted text -
>
> ---------------------------------------------
> Correct. Save in Tiff format instead. It can take monochrome.
> Regards,
> ImageAnalyst

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
image Ned Gulley 14 Nov, 2008 21:12:49
bmp Ned Gulley 14 Nov, 2008 21:12:49
rssFeed for this Thread

Contact us at files@mathworks.com