MATLAB: display RGB values of a fits image - matlab

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.

Related

How to smooth and extract an object from depth Image

I am using a dataset which provides depth images of human, I need to extract the object from this image or at least remove the other distortion in the image that not belong to the human body In Matlab.
a sample of images is shown below:
This is the output when I used
I = imread ('39.jpg');
human = sum(I,3)>10+10;
human
Any way to do that please?
thanks in Advance
For the image you show, where everything is grayscale but something is red, then just do:
so=imread('https://i.stack.imgur.com/hZOQv.jpg');
human=sum(abs(diff(single(so),1,3)),3)>20;
This essentially compares the difference in RGB values of the pixels, and gets the one above a threshold. If you have proper pngs, then the threshold should just be 1, however with jpg artifacts you may need a higher value, for this image 20 does the job.
There are some tiny artefacts in the result image, very likely due to jpg. When you do science, you need to store in png. If you have absolutely no other choice than jpg, then you may have artefacts.

Image segmentation algorithm in MATLAB

I need to implement an image segmentation function in MATLAB based on the principles of the connected components algorithm, but with a few modifications. This is intended for very simple, 2D images, with a background color and some objects in different colors.
The idea is that, taking the image as a matrix, I provide a tool to select the background color (it will vary for every image). Then, when the value of the color of the background of the image is selected, I have to segment all the objects in the image, and the result should be a labeled matrix, of the same size of the image, with 0's for the background, and a different number for each object.
This is a graphic example of what I mean:
I understand the idea of how to do it, but I do not know how to implement it on MATLAB. For each pixel (matrix position) I should mark it as visited and then if the value corresponds to the one of the background, assign 0, if not, assign another value. The objects can be formed by different colors, so in the end, I need to segment groups of adjacent pixels, whatever their color is. Also I have to use 8-connectivity, in order to count the green object of the example image as only one object and not 4 different ones. And also, the objects should be counted from top to bottom, and from left to right.
Is there a simple way of doing this in MATLAB? I know the bwlabel function, but it works for binary images only, so I'd like to adapt it to my case.
once you know the background color, you can easily convert your image into a binary mask of the same size:
bw=img!=bg_color;
Once you have a binary mask you can call bwlavel with 8-connectivity argument as you suggested yourself.
Note: you might want to convert your color image from RGB representation to an indexed image using rgb2ind before processing.

Dicom: Matlab versus ImageJ grey level

I am processing a group of DICOM images using both ImageJ and Matlab.
In order to do the processing, I need to find spots that have grey levels between 110 and 120 in an 8 bit-depth version of the image.
The thing is: The image that Matlab and ImageJ shows me are different, using the same source file.
I assume that one of them is performing some sort of conversion in the grey levels of it when reading or before displaying. But which one of them?
And in this case, how can I calibrate do so that they display the same image?
The following image shows a comparison of the image read.
In the case of the imageJ, I just opened the application and opened the DICOM image.
In the second case, I used the following MATLAB script:
[image] = dicomread('I1400001');
figure (1)
imshow(image,[]);
title('Original DICOM image');
So which one is changing the original image and if that's the case, how can I modify so that both version looks the same?
It appears that by default ImageJ uses the Window Center and Window Width tags in the DICOM header to perform window and level contrast adjustment on the raw pixel data before displaying it, whereas the MATLAB code is using the full range of data for the display. Taken from the ImageJ User's Guide:
16 Display Range of DICOM Images
With DICOM images, ImageJ sets the
initial display range based on the Window Center (0028, 1050) and
Window Width (0028, 1051) tags. Click Reset on the W&L or B&C window and the display range will be set to the minimum and maximum
pixel values.
So, setting ImageJ to use the full range of pixel values should give you an image to match the one displayed in MATLAB. Alternatively, you could use dicominfo in MATLAB to get those two tag values from the header, then apply window/leveling to the data before displaying it. Your code will probably look something like this (using the formula from the first link above):
img = dicomread('I1400001');
imgInfo = dicominfo('I1400001');
c = double(imgInfo.WindowCenter);
w = double(imgInfo.WindowWidth);
imgScaled = 255.*((double(img)-(c-0.5))/(w-1)+0.5); % Rescale the data
imgScaled = uint8(min(max(imgScaled, 0), 255)); % Clip the edges
Note that 1) double is used to convert to double precision to avoid integer arithmetic, 2) the data is assumed to be unsigned 8-bit integers (which is what the result is converted back to), and 3) I didn't use the variable name image because there is already a function with that name. ;)
A normalized CT image (e.g. after the modality LUT transformation) will have an intensity value ranging from -1024 to position 2000+ in the Hounsfield unit (HU). So, an image processing filter should work within this image data range. On the other hand, a RGB display driver can only display 256 shades of gray. To overcome this limitation, most typical medical viewers apply Window Leveling to create a view of the image where the anatomy of interest has the proper contrast to display in the RGB display driver (mapping the image data of interest to 256 or less shades of gray). One of the ways to define the Window Level settings is to use Window Center (0028,1050) and Window Width (0028,1051) tags. Also, a single CT image can have multiple Window Level values and each pair is basically a view of the anatomy of interest. So using view data for image processing, instead actual image data, may not produce consistent results.

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

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.

GLPaint - Save image as vector image

I am using CGColorSpaceCreateDeviceRGB() which returns a png image(pixel format)? Is there a way to save this image as a vector image. Basically I need to save the pictures drawn by the GLPaint application as a vector image.
I don't know anything about this function or about GLPaint, but you can't take a pixellized image and turn it into a vector image. Only humans and highly clever algorithms can do that ( see http://vectormagic.com/ )
If you have access to the input (gestures?) of GLPaint, you should convert them to SVG directly instead of passing through an RGB image.