resize image without imresize (MATLAB) [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
How to resize an image without using imresize in matlab

This code is done using nearest neighbor interpolation.
%# Initializations:
scale = [2 2]; %# The resolution scale factors: [rows columns]
oldSize = size(inputImage); %# Get the size of your image
newSize = max(floor(scale.*oldSize(1:2)),1); %# Compute the new image size
%# Compute an upsampled set of indices:
rowIndex = min(round(((1:newSize(1))-0.5)./scale(1)+0.5),oldSize(1));
colIndex = min(round(((1:newSize(2))-0.5)./scale(2)+0.5),oldSize(2));
%# Index old image to get new image:
outputImage = inputImage(rowIndex,colIndex,:);
You just need to change the scale factor accordingly..

Related

Shape recognition in MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Guys want write a basic code in matlab that recognizes basic shapes
Have converted a .png image to binary and then applied edge detection (Canny)
what to do next so that i can use the edge detected image to state that the image is a circle.
i = imread('h.png');
i= im2bw(i,0.5);
i=edge(i,'canny');
imshow(i);
what to do next???
you probably should learn about hough transform.
Matlab has already a function for circles imfindcircles (check out the examples!)
You could try using a neural net that was trained on a series of shapes. The nn can return a percentage accuracy so that you can see how well its doing for example.
function scan(img)
files = dir('*.jpg');
hist = [];
for n = 1 : length(files)
filename = files(n).name;
file = imread(filename);
hist = [hist, imhist(rgb2gray(imresize(file,[ 50 50])))]; %#ok
end
som = selforgmap([10 10]);
som = train(som, hist);
t = som(hist); %extract class data
net = lvqnet(10);
net = train(net, hist, t);
like(img, hist, files, net)
end
Can be tweeked to recognize shapes in an image.

How to measure the second derivatives of an image [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am at very first step in MATLAB programming and when I read an article about image processing, I see in most of them it has written that the first and/or second derivatives should be estimated.
How I can measure the second derivatives (Gxx,Gxy,Gyy) over the gradient?
Instead of applying successive differences, you could apply the second derivative kernel in each dimension:
Gx = [1 -2 1]; Gy = Gx'; %' y kernel is column vector
img = double(imread('cameraman.tif'));
Dxx = conv2(img,Gx,'same');
Dyy = conv2(img,Gy,'same');
If you were after a non-directional second derivative, you should use the Laplacian. A common kernel is:
L = [0 1 0;
1 -4 1;
0 1 0;] % fspecial('laplacian',alpha=0)
D2 = conv2(img,L,'same');
As in the comment above, you can use fspecial to get variations on the kernel that capture diagonal differences via the alpha parameter. Or you can use del2:
D2 = del2(img);
Look into imgradient from the Image Processing Toolbox. Two applications of that should give you what you want.
Something like this:
im = imread('cameraman.tif');
[Gx,Gy] = imgradientxy(im);
[Gxx,Gxy] = imgradientxy(Gx);
[Gyy,Gyx] = imgradientxy(Gy);
This uses a Sobel filter to compute derivatives. You can also use Prewitt, central differences or intermediate differences by passing this as a string to imgradientxy.
Hope that helps.

Quantification of cepstral coefficients for speech coder [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have been working on Homomorphic speech coder I have obtained the cepstral coefficients of the signal and the next step I have been asked to perform is quantize the coefficients using adaptive quantizer. I am not sure how to quantize the coefficients as its value ranges from -1.5 to 1.5, if i quantise it I just get 0 and 1 which i'm sure is wrong. What is the right way to quantise it.
I think when you are being asked to quantize the coefficients, you are being asked to set a resolution and quantize to that resolution. For example if you are to quantize to a 32-bit number, this would mean you would divide your range into 2^32 bins and quantize your values into those bins. For example:
offset = 1.5;
input_range = 3;
output_range = 2^32
quantized_value = round((value + offset) / input_range * output_range);
If you are being asked to use an adaptive quantizer that would mean that the resolution of the bins would be dynamic or the output bit width is variable. You would need to do more work to find what your goals are if you are going to write an adaptive algorithm for the quantization.

how can i find H(z) in this matlab code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i want to find H(z) in this code and print it.but i don't know how can i?
n=-11:11;
lp=(1/3)*sinc((1/3)*n);
wh=rectwin(23);
b=lp.*wh';
figure(1);
k=0:22;
stem(k,b);
title('N=23 FIR Filter impulse Response');
xlabel('Time');
ylabel('Mag');
figure(2);
[h,w]=freqz(b,1,1024);
plot(w/pi,20*log10(abs(h)));
grid;
title('LPF FIR -rectwin N=23 frequency response');
axis([0 1 -100 10]);
For a FIR filter with coefficients b(1), b(2), ..., the transfer function is the sum of b(k)*z^(-k+1) for k from 1 to len(b). See https://ccrma.stanford.edu/~jos/fp/FIR_Transfer_Function.html (The difference of +1 in the power of z is because Matlab arrays are indexed starting at 1, but the vector b in the link starts at b_0.)

How do i obtain only the first principal component in MATLAB? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
For certain measurements i need to obtain only the numeric value of the first principal component from the matrix. Can someone please tell me how do i go about it?
the most straight forward way is just to get the top eigenvector/value of your data's covariance matrix using eigs
say the data matrix x is N by D, or # of data by dimension of data
you can simply do
C = cov(X);
[V, D] = eigs(C, 1);
in fact, you can get the top k principal components by running
[V, D] = eigs(C, k);