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.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
The default graphs produced from matlab are very different from what I see in books. For example the image below looks visually pleasing. Can I change default settings of matlab to mimic this graphing style?
This question will refrain from lecturing the OP on best practices for graphics and simply attempt to answer the question as asked. I personally concur with a few of the concerns raised but leave it to the OP to seek out resources on data visualization and graphical aesthetics. (For the record, I'm not a fan of the chart.)
Resources:
The MATLAB Plot Gallery depicts a range of plots and adjustments that may help you. For high quality, professional looking graphs, scroll down to the Advanced Plots to see source code and the resulting figures.
Graphical overview of the Types of MATLAB Plots available.
You can also make a basic plot then use MATLAB's Plot Editor to customize the properties through the graphical interface. When done, click File-->Generate Code and you'll see one possible way to code that graph. This is helpful when you know how to do something through the interface but want to script it in the future.
Examples with code for Publication Quality Plots with Matlab
Mathworks blog on Making Pretty Graphs
Another example on Creating high-quality graphics in MATLAB for papers and presentations
I realize some of these links may eventually expire. Please feel free to comment if they do
Example:
I'm no expert. I learned everything in this answer from looking at the documentation, plot source code, and playing with the properties for the various plot components.
% Functions of Interest % MATLAB 2018a
fh=#(x) a + a*sin(b*x) + 1-exp(-b*x);
gh=#(x) a + (a/b)*cos(c*x);
a = 20;
b = .3;
c = .2;
% Plot
X = (0:.01:25)';
figure, hold on
p(1) = plot(X,fh(X),'r-','DisplayName','Excitation')
p(2) = plot(X,gh(X),'b-','DisplayName','Recovery')
% legend('show') % Optional legend (omitted here since we're adding text)
xlabel('X')
ylabel('Y')
title('Particle Displacement')
% Options
ha = gca;
box on
grid on
ylim([-80 100])
set(ha,'GridLineStyle','--') % use ':' for dots
t(1) = text(3.5,80,'excitation')
t(2) = text(12,20,'recovery')
for k = 1:2
p(k).LineWidth = 2.2;
t(k).FontWeight = 'bold';
t(k).FontSize = 12;
t(k).FontName = 'Arial';
end
Create a function which takes a matrix of data where each row represents a signal that you want to plot.
Define some styles you want to use for plotting. In your example plot, the first two would be 'bo' and 'rx'. Just iterate over your rows and plot each row with a different style followed by the command "hold on;"
function fancyplot(xaxis, matrix)
figure;
style = {'bo', 'rx', 'k.'}; # and so on
for r = 1:size(matrix, 1)
plot(xaxis, matrix(r,:), style{r});
hold on;
end
end
Write another script which you execute right after you plot or add it to the function above. In this script use the the following methods to control the limits of the axis
xlim
ylim
Set them to the min/max values of the data you plotted.
To add text to your plots use the Text command.
If you want to use these plots in publications be mindful of the fact that most publications are black and white and your graphs should be distinguishable event if they are not colored (I doubt the ones above would be). I always believed doing all formatting in code is a good idea without the manual tinkering around. Otherwise you might figure out that you have to update all 8 plots in your publication at 4 am shortly before you need to submit your paper. If you run some simulations and all formatting is in code you can simply execute your formatting scripts and save the plots automatically how to save a picture from code, preferably to the eps format.
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..
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.
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.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have trouble with the probability density function (p.d.f) of a log-normal distribution. I really need your help. As defined by wikipedia:
http://en.wikipedia.org/wiki/Log-normal_distribution#Probability_density_function
The probability density function of a log-normal distribution is:
My problem is, how to define x variable in MATLAB? Thanks for your help!
If you have the Stats toolbox, you can just use lognpdf:
y = lognpdf(x,mu,sigma);
Though this is a very simple function - fully vectorized, it's effectively just:
y = exp(-0.5*((log(x)-mu)./sigma).^2)./(x.*sqrt(2*pi).*sigma);
But you may want to check that x > 0 and sig > 0. To create this plot on the Wikipedia article that you cited, you can do:
mu = 0;
sigma = [1;0.5;0.25];
x = 0:0.01:3;
y = lognpdf([x;x;x],mu,sigma(:,ones(1,length(x))));
figure; plot(x,y);
When your question asks about defining x, maybe you're actually looking for log-normally distributed random variables, i.e., you want to sample randomly from the log-normal PDF/distribution? In that case you can use lognrnd:
r = lognrnd(mu,sigma);
I'm confused, like you can do this in a one-liner,
fun = #(x,mu,sigma) (1./(x*sigma*sqrt(2*pi))).*exp( -(power((log(x)-mu),2))/(2*power(sigma,2)))
x is any value that satisfies x > 0, the pdf tells you via Wikipedia
In probability theory, a probability density function (pdf), or
density of a continuous random variable, is a function that describes
the relative likelihood for this random variable to take on a given
value.
So any value x given to the log-normal pdf tells you tel relative likelihood that a random variable could be that value.
Consider this toy example:
mu = 1;
sigma = 10;
x = logspace(-2,0,10);
plot( x, fun(x,1,10) )
From this plot as x gets closer to zero, it's relative likelihood of actually taking on that value increases. DISCLAIMER I just threw that function together, it needs to be checked for accuracy, the preceding was for illustration only.