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 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.
> > 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 -
Use the "save" command, and save the variable M in a .mat file
> 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 = uint8(M) % (or uint16, uint32, etc)
then saving to a bmp will probably give you what you want
> > 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
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?
> 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
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:
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)?
> 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
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.
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.');
> 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