How to re size a too big image into small by keeping original values - matlab

I have an gray scale image of size <2559x3105 uint16>. when I try to open this image, I get warning that it is too big. I have tried imresize() function to make it small<512x512 uint8> in size. When I plot the original image and re-sized image, the intensity gets decreased after re-sizing. I want to re-size original image without changing in its pixel values. Is there any solution?

If you would like to keep your final image as uint8, I think you would be needed to first convert the uint16 image to uint8 image using im2uint8 -
uint8_image = im2uint8(uint16_image);
Then you may apply imresize on uint8_image.
But, if you don't want your final image to be of uint8 type, you can directly use imresize and it would keep the datatype, i.e. the resized image would be of uint16 type.

Read the docs and use the nearest neighbor method. That is,
resized = imresize(original, scale, 'nearest')
This will not use interpolated values. The downside is of course that edges might be jagged.

It sounds like your 16-bit image uses linear codes while the resulting 8-bit image needs to be gamma corrected. If this is the case you can use imadjust with a gamma parameter of 1/2.2 to produce the brighter image.

Do you get the warning when you display it with imshow? Does it say something like "Image to large to fit the screen, resizing to xx%"? If so, then you can simply ignore the warning. Otherwise, you can can set the 'InitialMagnification' parameter of imshow to resize the figure, but not the image itself.

Related

Rectified images of same size as the initial ones

I want to rectify a stereo image pair in MATLAB. To rectify, I use the following call:
[J1,J2] = rectifyStereoImages(I1,I2, cameraParamsStereo);
If I do this, then I only get the so called valid part of each image which is smaller than the initial image size. If I specify the argument OutputView as full, then I get rectified images which are larger than the original ones.
Is there a way to get rectified images that have the same size as the original ones?
It is possible in principle, but rectifyStereoImages does not support this.

Resizing command changes image shape

I have to resize image i.e if its dimension is 3456x5184 to 700X700 as my code needs image with less number of pixels otherwise it takes too much time to give results.So, when I use imresize command it changes the dimensions of image but at the same time it changes the shape of image i.e the circle in image which I also need to detect looks like oval instead of being cirle. I need your suggestions to resolve this problem. I am really grateful to you people.
Resizing images is done by either subsampling (to get smaller images) or some kind of interpolation (to get larger images)
Input is either a factor or a final dimension for width and height.
The only way to fit a rectangle into a square by simply resizing it is to use different scales for width and height. Which of course will yield in a distorted image.
To achieve what you want you can either crop a 700x700 region from your image or resize image using the same factor for with and height. Then you can fit the larger dimension into 700 and fill the rest around the other dimension with black or whatever you prefer.

When I write the image it appears black

I have a program that returns a grayscale image. But, when I try to write the image, it appears totally black. Why is that? How can I write the image and get the expected result?
Thanks.
First check on the type of your data. You can cast the type of the data by example double() or uint16() etc. (Check the help for typecasting).
Here is an example how you rescale your values to the intensity-range of uint16, unsigned integers with ~65k possible different values. The casting of course leads to less precision of the intensity values.
new_img(:,:) = uint16((new_img(:,:)./max(max(new_img(:,:),[],1)))*65536);
Afterwards you should be able to write the data to your file.
Make sure that your grayscaled image is of the right class. Furthermore check the values in the generated image. If they're simply too low all will appear black. If you can provide more specific information it might be possible to give a more elaborate answer.
if you're working on a binary image(before being converted to gray) and you about to convert it to gray-scale, then you suddenly change the range of pixels from [0, 1] to [0, 255]. so the value '1' in binary image is totally white but in gray-scale image is almost black.
try this:
img = imread('image_name.jpg');
imshow(img*50)
it make you sure that you image is black or just its pixel-values aren't appropriate.

MATLAB: display RGB values of a fits image

I want to read a .fits image of wide field sky and display the RGB values contained in a star. Can you please suggest a method to do so?
I have used fitsread to read in the image but i am not able to show the RGB values for specific locations(star).
In order to do this, you'll need a proper rgb fits file. The only .fits viewer I know of, ds9, does not support saving rgb fits files, but rather as the three separate (r,g,b) fits images. You can use "getpix" from wcstools (http://tdc-www.harvard.edu/wcstools/) or scisoft (http://www.eso.org/sci/software/scisoft/) on the individual frames. Note that "getpix" returns the pixel value given an image (x,y) location. ds9 does not provide the physical image location, but rather the wcs coordinates, so you may have to convert to image coordinates before calling getpix.

How to make image in double to be greyscale

I'll do the medical image processing with CLAHE method (I use the code in http://www.mathworks.com/matlabcentral/fileexchange/22182-contrast-limited-adaptive-histogram-equalization-clahe/all_files ) and region growing ( http://www.mathworks.com/matlabcentral/fileexchange/19084-region-growing/content/regiongrowing.m )
that function can run if i use double data type for image. but converting image to double make its to be the binary image.
anyone know how to make image still in double but not to be a binary image?
If your image is img then do im2double(img). See im2double on the mathworks reference site.
If I've understood your comment correctly, you're trying to convert a binary image to a gray scale image. If so, this is not possible, as you've thrown away all the intensity information in lieu of a simple 0/1 image.
If your question was on how to convert a color/grayscale image to double, then LightningIsMyName has the answer for you. Here's a small example that you can play around with to see what you really want:
img=imread('peppers.png'); %#read in MATLAB's stock image
imgDouble=im2double(img); %#convert uint8 to double
imgGray=rgb2gray(img); %#convert RGB image to grayscale
imgGrayDouble=im2double(imgGray);%#convert grayscale image to double.
Here's how your color and grayscale images should look like: