I am trying to use imhist to display the histogram of a uint8 .jpg, however I am getting this error:
Error using imhist Expected input number 1, I or X, to be
two-dimensional.
Error in imhist>parse_inputs (line 278) validateattributes(a,
{'double','uint8','int8','logical','uint16','int16','single','uint32',
'int32'}, ...
Error in imhist (line 60) [a, n, isScaled, top, map] =
parse_inputs(varargin{:});
Here is my image information:
whos f Name Size Bytes Class
Attributes
f 2988x5312x3 47616768 uint8
Do I need to convert my image to another data class? I would appreciate any help on this.
Thanks!
The cause of error is because your image is RGB and imhist does not deal with that. To work around this you can either use a single channel:
imhist(YourImage(:,:,Channel));
or convert from RGB to grayscale:
imhist(rgb2gray(YourImage));
That should work fine now.
Related
I have tried to calculate adjacent pixel correlation of 2 images. I am getting the answer for the encrypted images but not for the original plain text image.
It's showing some error which i am unable to understand. I have given the code which i used below along with the error message.
Please help.
P = imread('cameraman.tif');
x1 = P(:,1:end-1);
y1 = P(:,2:end);
r_xy1 = corrcoef(x1,y1);
scatter(x1,y1);
For this I am getting an error message:
Error using bsxfun Mixed integer class inputs are not supported.
Error in cov (line 93) xc = bsxfun(#minus,x,sum(x,1)/m); % Remove
mean
Error in corrcoef>correl (line 209) r = cov(x);
Error in corrcoef (line 92) r = correl(x);
Error in apc_PT (line 4) r_xy1 = corrcoef(x1,y1);
The same code worked for encrypted image. Dont know what's wrong.
You should cast the result of imread to double:
P = double(imread(...));
This will fix your error with corrcoef.
Edit Also, as noticed in the comments you have to use vectors in scatter:
scatter(x1(:), y1(:));
Best,
I'm trying to blur a grayscale image using Gaussian low pass filter( 5*5 kernal).I tried the following code.
I = imread('Lena.png');
G = fspecial('gaussian',[5 5],2);
Ig = imfilter(I,G,'same');
imshow(Ig);
But I'm getting an error in file 'meshgrid.m' as follows.
Error: File: meshgrid.m Line: 1 Column: 5
The input character is not valid in MATLAB statements or expressions.
Error in fspecial (line 145)
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
Error in Untitled2 (line 2)
G = fspecial('gaussian',[5 5],2);
I'm not understanding what the error is.Can anyone help me please.The input image that I used is uploaded below('Lena.png').Thanks in advance
I tried the quadtree decomposition using the following code, but every time I am getting an error.
>> I=imread('hyd.tif');
>> S=qtdecomp(I)
Or
>> I=imread('hyd.tif');
>> S=qtdecomp(I,.27)
Error:
??? Error using ==> qtdecomp>ParseInputs at 145
A must be two-dimensional
Error in ==> qtdecomp at 88
[A, func, params, minDim, maxDim] = ParseInputs(varargin{:});
The culprit is due to your image being in colour or RGB. Try converting the image to grayscale before using the algorithm.
I = imread('hyd.tif');
Igray = rgb2gray(I);
S = qtdecomp(Igray);
Also make sure that your image dimensions are of a power of 2 or else the quadtree decomposition algorithm will not work.
link b.jpg
i=imread('b.jpg');
i1=rgb2gray(i);
i2=im2double(i);
j=log(1+i2);
1.
now this for get histograme of image.
imhist(j);
say error:
??? Error using ==> iptcheckinput
Function IMHIST expected its first input, I or X, to be two-dimensional.
Error in ==> imhist>parse_inputs at 270
iptcheckinput(a, {'double','uint8','logical','uint16','int16','single'}, ...
Error in ==> imhist at 57
[a, n, isScaled, top, map] = parse_inputs(varargin{:});
=============================================================================
2.how can draw diagrame of function?
plot(j,i2);
??? Error using ==> plot
Data may not have more than 2 dimensions
==============================================================================
3.how can get gamma of j
I think, you have made a mistake in the beginning
i=imread('b.jpg');
i1=rgb2gray(i);
i2=im2double(i); % POSSIBLE MISTAKE
i2=im2double(i1);
j=log(1+i2);
After this correction, both (1) imhist(j) and (2) plot(j,i2); work OK. For gamma correction you can refer to either of these : Link-A, Link-B.
I have a quick question. I'm trying to compute an images 2D gradient using the gradient() function in MATLAB, but its not working. Specifically, here's my code (The image I'm using is grayscale):
im = imread('C:\yosemite1.bmp');
g = FindImageGradients(im);
I get the following error:
??? Error using ==> rdivide Integers
can only be combined with integers of
the same class, or scalar doubles.
Error in ==> gradient at 75
g(2:n-1,:) = (f(3:n,:)-f(1:n-2,:))./h(:,ones(p,1));
Any clues on how to solve this ?
Your image data is probably being read as integers in the range [0,255] (for 8 bit per color channel), so the type of im is uint8 or other int type. Try converting it to single or double:
g = FindImageGradients(single(im));