Error using imcontrast tool in MATLAB - image

I have a problem with imcontrast tool.
I read 2D dicom image, then convert it to 16bits(im2uint16) and perform filtration and windowing using imcontrast.
It shows me a warning message:
How Can I prevent then ?
How can I change data range in imtool ?
I would appreciate for any help please.

The [0,51156] is the range of the image data which change from image to image. [0, 65535] are the default color axis limits for uint16, which are outside the image data range, causing the re-adjust warning prompt. If you wish to silence the prompt you can manually set the color axis limits before calling imcontrast by:
caxis([double(min(min(Image))), double(max(max(Image)))]);
The conversion to double is to prevent a datatype mismatch. max() and min() return an uint16 value with uint16 data, which causes an another error down the line.

Related

display .raw image in matlab

I have MATLAB code to read raw data and I can display it using 'uint16' like this:
But when I try to change 'uint16' to 'uint64' I get this:
I want to display my image like the 16bit image with using 64bit. Is there a way to do that? My code is here:
clear all;
I=fopen('data.raw');
A=fread(I,[2048 1536],'uint16');
imagesc(A.');
newmap = contrast(A);
colormap(newmap)
Ask yourself why do I want to use 64-bit ? A color is generally RGB888, 8-bits per components ... you can read the image in uint16 and then use this data in 64-bit floating point (double) format ... is that what you are trying to do ?

Setting MATLAB's default colormap

I am preparing some figures for a paper printed in black and white. I thought that easiest way to do so was to change the default colormap to gray. However I'm stuck with the following error:
set(0,'DefaultFigureColormap',gray);
Error using set
Value must be either:
an Mx3 array of type single or double in the range [0 1]
an Mx3 array of type uint8
You can use the built-in function rgb2gray to convert from RGB. There are other such alternatives mentioned in the Image Processing Toolbox.

how we save multiple images by using imwrite

can anyone help me to save my resulted images by using imwrite
source = 'C:\Y\';
im_number=5;
for i=1:5
image{i}=im2double(imread([source,'Carbon_', num2str(i)],'tif'));
image{i}=double(image{i});
B{i}= Sftfun(image{i});
B{i}=uint32(B{i});
imwrite(B{i},[source,'face_', num2str(i)],'tif');
end
The problem with your code is that you are casting your image to uint32. If you are trying to save your image as a TIF file, you can only save it as 8-bit or 16-bit. Consulting the MATLAB documentation, you can only save with these two bit depths. 32-bit depths are not supported.
Consult the MATLAB documentation for more details: http://www.mathworks.com/help/matlab/ref/imwrite.html
As such, either cast the image as 8-bit or 16-bit (through im2uint8 or im2uint16), or normalize your image so that it goes from [0,1] (through im2double).
I also have some comments about your code that do need fixing for readability:
Do not save your images to a cell array called image. MATLAB has a built-in command called image which takes in a matrix and displays it to the screen for you as an image. Bear in mind this is not the same as imshow. By doing this assignment, you will shadow over the actual image command, and so any scripts that rely on this function will result in an error.
im_number seems to be an unused variable. I'm not sure what its purpose is, but I'd say it's safe to remove this statement as well.
Get rid of the following statement as you are already converting the image to a double type in the previous line:
image{i} = double(image{i});
Aside
It seems that you have asked a similar question here: save tif 32 bit images by using imwrite
This question has already been resolved in that you are not able to save 32-bit images using imwrite. However, someone in this thread has posted a workaround for you to use in MATLAB. Try using that instead of imwrite.

reading SVM training dataset

I want to read a training image set for SVM training. This is the code
%Location of the image.
Class1 = 'Training/11';
% load the dataset
dirList = dir(fullfile(Class1,'*.ppm'));
%dirList
files={dirList.name}';
The type of files that I got is of type cell. How I can access those images to perform something, like show it and do feature extraction??
When I tried to show it:
figure, imshow(files)
I got this error
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64,
logical
Instead its type was cell.
Error in imageDisplayValidateParams (line 12)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in imageDisplayParseInputs (line 79)
common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 220)
[common_args,specific_args] = ...
Do you know how to access and do some processing of these images in files?
MY FOLDER DIRECTORY!!
MY DIRECTORY
Inside my training Folder
First off, imshow requires an actual image as its input. You are specifying a cell array of strings. On top of that, you can only show one image at a time. Try accessing individual cell elements instead and using those to read in an image and display them on the screen.
im1 = imread(files{1}); % Read in first image
imshow(im1); % Show the first image
figure;
im2 = imread(files{2}); % Read in second image
imshow(im2); % Show the second image
If you want to display all of them, you could try using a combination of imshow and subplot.
Let's say you had 9 images, and wanted to organize them in a 3 x 3 grid. You could do something like:
figure;
for i = 1 : 9
subplot(3, 3, i);
im = imread(files{i});
imshow(im);
end
Now for performing feature extraction, my suggestion is that you take a look at the Computer Vision toolbox that is accompanied with MATLAB. There is a whole suite of tools that performs feature extraction for you. Things like MSER, SURF, HOG and methods to match keypoints between pairs of images.
Check this link out: http://www.mathworks.com/products/computer-vision/code-examples.html

image is too big to fit in the screen (MATLAB)

I got an error in Matlab which is
Warning: Image is too big to fit on screen; displaying at 33%
and my source code for this part is this :
watermarked_image_uint8=uint8('watermarked_image');
%# write watermarked Image to file
imwrite(watermarked_image_uint8,'watermarked_image','jpeg');
%# display watermarked image figure(1)
imshow(watermarked_image), title('Watermarked_Image')
Can any one help me please to debug this warning?
It's not an error, just a warning that the resolution of the image you are showing is larger than the resolution of your Matlab window, so Matlab has to reduce the size of the image before displaying it.
It has nothing to do with your code, and it won't effect your results, so you can safely ignore it.
As Ghaul said, the warning is nothing to worry about. Use the InitialMagnification argument to imshow to make your image smaller, or turn the warning off, if it annoys you.
You should probably try to change the resolution of your image so that it would fit in your screen. To check for your screen resolution check this site :
http://www.whatismyscreenresolution.com/
Try using images with lower or the same resolution with your monitor. To change the resolution of your image you can use paint or any photo editors.
Hope it helps.
I guess you could do something like get first the size of the screen, create a figure and then set the your window size, for example:
plot_size = get(0,'ScreenSize');
fg = figure(1);
set(fg, 'Color', [1 1 1], 'Position', plot_size, 'Visible', 'on');
imshow(watermarked_image),
title('Watermarked_Image')
this is simply warning you are facing, so either identify the unique number of warning and then suppress it or you can use
imshow(watermarked_image, 'InitialMagnification', 50);
this will help you to reduce the size of your image and fit it on the screen.
I also found this error when running from the command line with the -nodisplay argument (what I really wanted was -nodesktop).

Resources