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.
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
cc=imread('<a href=“http://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Pavlovsk_Railing_of_bridge_Yellow_palace_Winter.jpg/250px-Pavlovsk_Railing_of_bridge_Yellow_palace_Winter.jpg”>wintersm.jpg</a>');
c=rgb2gray(cc);
x=ones(256,1)*[1:256];
c2=double(c).*(x/2+50)+(1-double(c)).*x/2;
c3=uint8(255*mat2gray(c2));
t=graythresh(c3);
ct=im2bw(c3,t);
This is a code i have written to threshold the image but cant execute because of the error " ==> times
Matrix dimensions must agree. " . I am new to matlab and i cant figure out how to solve this problem. Please Help.
I looked at the image, it is of size 169x250 . Hence size(c) = [169 250] while size(x) = [256 256]. Since .* operation between c and x needs both of them to be of same size , hence it is giving the error.
Redefine x so that its size matches the size of c
I ran your code but added the following line before c2=double(c).*(x/2+50)+(1-double(c)).*x/2;, I added this:
size(x)
size(c)
and you get the following print out:
ans =
256 256
ans =
169 250
Which is essentially saying, the image isnt the size you think it is and you are mixing your matrix sizes.
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 am trying to implement sequentialfs for feature selection. I saw this post : Sequential feature selection Matlab
Tried to follow the example given as the solution to implement.
My TrainVec is a matrix of dimension 268 x1475 whereas TestVec is 116x1475 and TestLabel is 116 x 1 and TestLabel is 268 x 1.
the code i implemented is
f = #(TrainVec,TrainLabel,TestVec,TestLabel) sum(TestLabel ~= predict_label);
fs = sequentialfs(f,Vec,Label);
The error i get is :
??? Error using ==> crossval>evalFun at 505
The function
'#(TrainVec,TrainLabel,TestVec,TestLabel)sum(TestLabel~=predict_label)'
generated the following error:
Matrix dimensions must agree.
Error in ==> crossval>getFuncVal at 524
funResult = evalFun(funorStr,arg(:));
Error in ==> crossval at 363
funResult = getFuncVal(1, nData, cvp, data, funorStr, []);
Error in ==> sequentialfs>callfun at 495
funResult = crossval(fun,x,other_data{:},...
I have checked all my matrixes and ensured that they are of same dimensions. Not sure what is wrong. Need some guidance.
Error in ==> sequentialfs at 357
crit(k) = callfun(fun,x,other_data,cv,mcreps);
I'm not sure here if predict_label is a variable or a function with zero input arguments. I would guess that if it's a variable, it's not the same size as TestLabel; and if it's a function, it's either not returning something the same size as TestLabel or it has some intermediate calculation that is erroring.
Either way, you would typically want to be writing
f = #(TrainVec,TrainLabel,TestVec,TestLabel) sum(TestLabel ~= predict_label(TrainVec,TrainLabel,TestVec));
where predict_label is now a function that takes in your TrainVec and TrainLabel, builds a model, evaluates it on TestVec, and returns an array of predicted labels of the same size as TestLabel.