When I try to run
BW = edge(im,'canny')
where im is my image (256X256 uint8).
This is the error I get:
Error using gradient (line 3)
Not enough input arguments.
Error in edge>smoothGradient (line 709)
derivGaussKernel = gradient(gaussKernel);
Error in edge (line 213)
[dx, dy] = smoothGradient(a, sigma);
Error in ps_1_1 (line 2)
BW = edge(im,'canny')
As the function works fine for me when I tested it I think you probably pass an image to the function which is not grayscale (meaning each pixels having one gray value), if that is not the case either, try to reinstal the library because as antony mentioned in the comments, the function works fine. but anyway be sure to read the edge document carefully.
Related
I have an image and I want to convert that image into gray. After that, I tried to display that gray image in GUI but it became exactly look like a rainbow. How can I display a gray image in GUI? I tried the below code but it does not work. Please help
X = imread('j3.jpg');
X=rgb2gray(X);
axes(handles.axes1);
imshow(X)
But I got the following error:
Error using matlab.ui.Figure/set
While setting the 'Colormap' property of 'Figure':
Value must be either:
an Mx3 array of type single or double in the range [0 1]
an Mx3 array of type uint8
Error in images.internal.basicImageDisplay (line 71)
set(fig_handle, 'Colormap', map);
Error in imshow (line 293)
hh = images.internal.basicImageDisplay(fig_handle,ax_handle,...
Error in gray>pushbutton1_Callback (line 83)
imshow(X)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gray (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)gray('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
What is the issue and how can it be resolved?
It appears that you have named your GUI gray.m which conflicts with the builtin gray function which provides the grayscale colormap (the default for imshow). As a result, when MATLAB tries to create the grayscale colormap (colormap(gray)), it instead calls your GUI and the output is not what colormap is expecting, resulting in the error that you've shown.
You will need to rename your GUI to something else and you should have no issues.
This code produces error:
validateattribute(I{'logical','unit8'.....
Please anyone can tell me why this is so..
I = imread('flowers.jpg');
I=im2double(I);
points = detectSURFFeatures(I);
imshow(I); hold on;
plot(points.selectStrongest(10));
detectSURFFeatures takes grayscale images. If your image is RGB, you should call rgb2gray frist.
The error message should be telling you something to that effect.
I am working with dicom chest PA's. I have no problem loading the images and doing basic thresholding work, however I need to apply some filters. I will be designing my own filters in the future but for now I want to use the MATLAB ones. The images are 16bit and in MATLAB docs it says that fspecial works fine with 16bit images.
When I try using fspecial or the edge functions i get similar results to the images as shown below.
My question: why is this happening and how do i fix it?
Your help is appreciated.
Regards,
full_path = 'I:\Find and Treat\Anonymized_Data\000026_20050607112512_1.dcm';
dicominfo_image = dicominfo(full_path);
dicomread_image = dicomread(dicominfo_image);
dicomread_image = mat2gray(dicomread_image);
c = imcomplement(dicomread_image);
figure,
subplot(1,3,1)
imshow(c)
f = fspecial('laplacian');
cf = filter2(f,c);
subplot(1,3,2)
imshow(cf)
f1 = fspecial('log');
cf1 = filter2(f1,c);
subplot(1,3,3)
imshow(cf1)
EDIT
I added and modified the following code to take into account the dynamic range and plotted a mesh plot i obtained the following result and error message.
Warning: Error updating LineStrip.
Update failed for unknown reason
Warning: Error updating LineStrip.
Update failed for unknown reason
figure,
subplot(2,3,1)
imshow(c, [])
f=fspecial('laplacian');
cf=filter2(f,c);
subplot(2,3,2)
imshow(cf, [])
f1=fspecial('log');
cf1=filter2(f1,c);
subplot(2,3,3)
imshow(cf1, [])
subplot(2,3,4)
mesh(c)
subplot(2,3,5)
mesh(cf)
subplot(2,3,6)
mesh(cf1)
EDIT
LINK TO IMAGE FILE
Your images are just too big.
The Laplacian operator is a 3x3 matrix that approximates the second derivative of the images. Your image is 2700x2200 which means that the variability of the pixels in that small size(comparing to the whole image) is neglectable. You can see it better if you plot your Laplacian filter image as imshow(cf(300:end-300,300:end-300), []) removing the boundaries (where you actually have a big gap). To solve this you'll need to or redefine a Laplacian filter with a higher dimension or resize the image you have to a lower size (imresize is your friend).
The same happens with the log filter, but in this case you can do something about it. The default log filter returned by fspecial is 5x5, but you can actually ask fspecial to create bigger filters.
If you call it the following way:
f1=fspecial('log',50,0.3);
cf1=filter2(f1,c);
imshow(cf1, [])
You get the next figure, that looks kind of a good log filter result.
Hi all I am using montage command of matlab to display images. However I am facing a problem. The command that I use is given below:
dirOutput = dir('C:\Users\DELL\Desktop\book chapter\Journal chan vese\robust
contour initialization\book for document\4 phase\*.jpg');
fileNames = {dirOutput.name}'
montage(fileNames, 'Size', [1 6]);
export_fig combined1.jpg -r300
I have 6 images (all grayscale). However, the command prompt immediately throws an error like this:
//Error using montage>getImagesFromFiles (line 349)
//FILENAMES must contain images that are the same size.
//Error in montage>parse_inputs (line 225)
// [I,cmap] = getImagesFromFiles(varargin{1});
//Error in montage (line 112)
//[I,cmap,mSize,indices,displayRange] = parse_inputs(varargin{:});
//Error in montage_pics (line 3)
//montage(fileNames, 'Size', [1 6]);
I am even uploading some of my images here:
As can be seen clearly, all the images are grayscale. I then read the image size and they are as follows:
1.128X128 2.128X128*3 3.128X128*3 4.128X128 5.128X128*3 6.128X128*3.
So some of the images are treated as indeed colour images.
My question is how to use the montage command for such images. Another problem is that montage command always needs images of similar sizes. So I wanted to avoid this loopholes.
Of course I could use a software tool to convert the images to the required format but that is a bad way to work. I believe the below code if added to my original code will solve this problem
%Read Each Image
I=imread('image');
I=imresize(I,[128 128]);
I=I(:,:,1);
%Apply montage command
However I have failed to integrate this code in my original code. Please help me to solve this problem. Thanks in advance guys for your valuable suggestions and help.
To montage you have to make sure
The size matches
The datatype matches
All images are grayscale (or all images are rgb, but do not mix)
.
images={'eight.tif','fabric.png','football.jpg'};
%intended size
ssize=128;
%preallocation
IALL=zeros(ssize,ssize,1,numel(images));
for idx=1:numel(images)
%get image, ensure double to avoid issues with different colour depths
I=im2double(imread(images{idx}));
%resize
I=imresize(I,[ssize,ssize]);
%if rgb, change to gray
if size(I,3)>1 %rgb image
I=rgb2gray(I);
end
%insert
IALL(:,:,:,idx)=I;
end
montage(IALL);
How can I use the qtdecomp(Image,threshold) function in MATLAB to find a quadtree decomposition of an RGB image?
I tried this:
Ig = rgb2gray(I); % I is the rgb image
S = qtdecomp(I,.27);
but I get this error:
??? Error using ==> qtdecomp>ParseInputs
A must be two-dimensional
Error in ==> qtdecomp at 88
[A, func, params, minDim, maxDim] = ParseInputs(varargin{:});
Also I get this error:
??? Error using ==> qtdecomp>ParseInputs
Size of A is not a multiple of the maximum block dimension
Can someone tell me how can I do it?
One obvious error... In the code above you are still passing the original RGB image I to the QTDECOMP function. You have to pass Ig instead:
S = qtdecomp(Ig,.27);
There are two problem with the code in your original post:
1) The first error is because you need to supply Ig, the greyscale version of your image to the qtdecomp function, rather than the colour version I:
S = qtdecomp(Ig, .27);
2) The second error is because for the function qtdecomp, the image's size needs to be square and a power of 2. I suggest you resize the image in an image editor. For example, if your image is 1500x1300, you probably want to resize or crop it to 1024x1024, or perhaps 2048x2048.
You can find the size of the greyscale version of your image with this MATLAB command:
size(Ig)
To crop it to the 1024x1024 in the top-left corner, you can run this MATLAB command:
Ig = Ig(1:1024, 1:1024);