How to make image in double to be greyscale - matlab

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:

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.

To substitute lsb value of rgb image with character

I want to substitute LSB of rgb image with character. I have done it for gray sacle image using bitset and bitget. Can I use same logic for rgb image?
Here is part of code which I have used:
stego=zeros(size(img))
stego=bitset(stego,1,lsp)
Where img is cover image and lsp is binary message. I have then merge bitplanes by:
stego=bitset(stego,2,bitget(img,2))
Up to 8th plane to get the strgo image.
How can I build the same logic for RGB image? Please guide me.

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.

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.

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.