Matlab image file convert from *.PPM into *.PGM? - image

I have dataset of training images in .ppm format.
But when I want to extract the feature using SIFT descriptor from Lowe, I have an problem.
Because my training images dataset is in *.PPM format, but to use SIFT function from lowe, the images required is in *.PGM format.
Everytime I give my *.PPM image file, I always get this error
Error using '
Transpose on ND array is not defined.
Error in sift (line 38)
fwrite(f, image', 'uint8');
I know that I can convert my *.PPM image inti *.PGM by using
imwrite(image,'test.pgm')
But it means, that I'll make new file with *.PGM format, And I dont need it..
Any idea??

Related

Extract a whole scale image from a SVS format file in C++

I am trying to extract a whole scale image from a SVS file in C++.
I saw an explanation from the OpenSlide homepage.
It says the SVS format is "single-file pyramidal tiled TIFF".
So I tried to extract a whole-scale image like I did for TIFF image: I read all IFDs from the SVS file, but there is no 273 tag which contains an address pointing to a whole scale image.
That's why I am little confused now, the SVS format doesn't have a whole scale image inside the file?
I found an undefined private tag from a SVS file which number is 34675. Is this tag is for a whole scale image?
Or is there a proper way to extract it?
Aperio SVS is a tiled format. All levels of the pyramid are tiled images. The base layer is the first TIFF directory. This page of the LibTiff documentation shows how to read tiled images.
In short, you need to look for tag 324 (TIFFTAG_TILEOFFSETS), as well as tags 322 and 323 (TIFFTAG_TILEWIDTH, TIFFTAG_TILELENGTH). I highly recommend you use LibTiff for this, and don’t try to roll your own.
The custom tag in the SVS file contains metadata, including the physical size of a pixel in micron (SVS doesn’t set the resolution TIFF tags).
You can read out the thumbnail image (is this what you mean by whole scale image?) as an openslide associated image.
For example, libvips has a convenient openslide binding written by the openslide authors:
$ vipsheader -f slide-associated-images CMU-1.svs
label, macro, thumbnail
Lists the images in the SVS file. macro is the huge pyramid that you get by default, thumbnail is the small overview, label is the shot of the slide label.
Get the thumbnail like this:
$ vips copy CMU-1.svs[associated=thumbnail] x.jpg
To read as a JPG image.
In C++, you could write:
VImage thumb = VImage::new_from_file("CMU-1.svs",
VImage::option()->set("associated", "thumbnail"));
thumb.write_to_file("x.jpg");

Reading a PGM file in Matlab

I'm trying to run the command:
[face,MAP]=imread('face1.pgm');
but I get an empty array for MAP. I was able to successfully read the file data into face though.
PGM is a grayscale image format. There is no colormap. Were you expecting one? The normal behavior for imread is to return an empty colormap if the file didn't contain one.

Converting image to data file (.dat) in matlab

Is there a way in matlab to convert an image file i.e; .png to .dat file?
It depends on the format of your .dat file. .dat is not a standard extension so you can get this from somewhere or design your own writer and reader. In terms of reading the .png you can just use matlabs imread('filename') function. This will return a NxMx3 matrix of the image and RGB values.
I would suggest combining the RGB values into a single float value and then using dlmwrite or csvwrite to store it. If you want to manipulate the image first that will be up to you.

gray levels are changed after using imsave function

I used these codes to produce an RGB image with gray levels between 50 and 170.
a='C:\Users\sepideh\Desktop\IP_abadpour\S45C-113050518040.jpg';
b=imread(a);
b=b+50;
b(b>170)=170;
and you'll see when I call functions max and min, it is proved that the gray levels are between 50 and 170.
max(max(max(b)))
ans =
170
min(min(min(b)))
ans =
50
then I used imshow and imsave functions to save the image with the name "50to170"
c=imshow(b);
d=imsave(c);
Now I read the written image in this way:
a='C:\Users\sepideh\Desktop\IP_abadpour\50to170.jpg';
b=imread(a);
This time when I call max and min functions,I see:
max(max(max(b)))
ans =
235
min(min(min(b)))
ans =
16
I mean it seems that gray levels have been changed after using imshow and imsave functions!
Why does it happen?
Is it because of the format (.jpg) that I'm using when employing imsave function?
Instead of using imsave, use imwrite
b=imread(a);
b=b+50;
b(b>170)=170;
imwrite(b,'50to170.png','png')
Notice that I am saving it as a png file instead of a jpg to prevent compression. Bitmap also saves it without compression.
This method is a more direct way to save raw image matrices than using imshow and imsave.
If you want the same functionality of imsave (selecting where the file goes) check out "uiputfile" to get file name and location.
I tested it.
1.First of all you can't use imsave(b) because the function imsave expects its first input argument to be a valid handle to a single graphics object.So first you should show the image in form c=imshow(b) and then use c as an input for function imsave.
2.If you want to save the image without showing it first use function "imwrite" and pass b as the first input argument to it.
Note that if you don't want gray levels be changed after saving, you should use 'bmp' as the save format not 'jpg'.
Because 'jpg' does not support indexed images and "imwrite" converts indexed images to RGB before writing data to JPEG files so the gray levels might be changed.It's not related to the contrast stretching when showing the image in matlab.It's related to the format used to save the image.

Reading a .dat image file

I have an image stored in .dat format an I want to read and then show the image. imshow and imread functions don't work.what are the other functions that I can use?
Note that I'm using Matlab R2010a
The load function should work
load("filename.dat")

Resources