How to convert a structuring element to an binary image? [closed] - matlab

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 9 years ago.
Improve this question
How can you convert a structuring element to an binary image in MATLAB? For example, say I need to convert a square structuring element
se = strel('square',7)
Kindly help me in this matter. I really need a method or algorithm.

Use the getnhood method of the strel class:
NH = se.getnhood()
Returns an array NH as defined by the strel se. NOTE: NH is a binary (logical) image (matrix). You can display it as is or you can pad it as suggested by Jigg.
For future reference, you can use tab command completion to see the available methods for a class (hit TAB after typing se.), or you can use methods(se) to get a full list of available methods.

Technically, the array given by chappjc's code is a binary image.
Try displaying it like that:
nh = se.getnhood();
p=padarray(nh, [10 10], 0, 'both'); % This pads the array with zeros
imshow(p);

Related

Matlab - plot data from array of structs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array of structs. Every struct holds a set of data for one single measure. Matlab gives me an error when I try to plot this data.
Expected one output from a curly brace or dot indexing expression, but there were 361 results.
How should I rewrite my plot code?
plot(result.structArray_A(:).nonArrayValue_X, result.structArray_A(:).nonArrayValue_Y);
I have found a solution. Simply writing the following does work, even if the syntax does look odd:
plot([result.structArray_A.nonArrayValue_X], [result.structArray_A.nonArrayValue_Y]);

matlab draw a line using user input values [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
I want to draw a line using the inputs for values x1,y1 and x2,y2 from the gui edit text box and plot them on the axes.
function
You are trying to convert the graphics handle itself to a number rather than converting the contents of the uicontrol to a number. To get the value, you'll want to use the 'String' property of the uicontrol instead.
x1 = str2double(get(handles.edit1, 'String'));
You will want to do the same for all user-supplied values.

I is not a real numeric array of class SINGLE [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'm using the computer vision: VLfeat library to compute a HOG descriptor of an image, and after inputing this code:
cellSize = 8 ;
hog = vl_hog(im, cellSize, 'verbose') ;
I get this error in MATLAB, and when I google it I really can't find any possible explanation:
Error using vl_hog
I is not a real numeric array of class SINGLE.
After going over the code (found here) I'm also not sure what the variable I is:
Hopefully, I haven't missed something elementary ...
library source
As the asker already found out, the I refers to the first input argument.
Hence this should solve the problem:
hog = vl_hog(single(im), cellSize, 'verbose')

Matlab: how to redefine indexing to begin from zero? `Subscript indices must either be real positive integers or logicals.` [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 9 years ago.
Improve this question
I have a mathematical data where it would be very convenient to have the index to start from zero like
a=sparse([],[],[],30,1);
>> a(0)=someValueHere
Subscript indices must either be real positive integers or logicals.
but Matlab by default offers only the index to start from 1. Is there some easy hack or trick by which I could still assign a(0) so that I don't need to create a dummyVar a0 for the value or append the value at the end?
So how to get assignment such as a(0) in Matlab? Every time zero-index called catch the error and return someValueHere instead of the warning?
To get MATLAB's index to start from 0 you'll need to make an large set of object classes that emulate regular numeric classes, but behave differently with functions such as subsassgn(), subsref() etc.
Maybe someone was crazy enough to do it somewhere, I'd expect this to take weeks to months of work to actually work properly.
There is a discussion on the matlab index issue: http://www.mathworks.cn/matlabcentral/newsreader/view_thread/285566
Maybe you can write a function like
function t=C_index(x)
t = x + 1;
Then you can write something like y(C_index(0)) to get the first value in vector y.
In Addition,
t=#(x) x+1
y(t(0))
should work.

How to apply sliding window for subtracting two different images in matlab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to apply sliding window for subtracting two different images in matlab,
the window size must be 4X4,
please help me
i want to find similarity value between two different images.if A and B are two 2 images take difference between each 4x4 matrix of each A&B in sliding window manner
i tried a code ,i dont know whether it is correct or not
m=imread('index.jpeg');
sal=imread('salt.jpg');
salt=rgb2gray(sal);
ab=rgb2gray(m);
imshow(ab);
imh=size(ab,2);
imw=size(ab,1);
wh=4;
ww=4;
k=0;
disp(imh),disp(imw);
if 1
for j=1:imh+wh-1
for i=1:imw+ww-1
w1=ab(j:j+wh-1,i:i+wh-1,:);
w2=salt(j:j+wh-1,i:i+wh-1,:);
w3=w1-w2;
disp(w3);
disp('next mat');
end
k=k+1;
disp(k);
end
end
The upper bounds of your for-loops are the cause for your troubles.
You specify:
imh=size(ab,2);
imw=size(ab,1);
However, your for-loops have these conditions:
j=1:imh+wh-1
and
i=1:imw+ww-1
So you move past both the 'height' and the 'width' dimension.
Try this instead:
for j=1:imh-wh
for i=1:imw-ww
w1=ab(j:j+wh,i:i+wh,:);
w2=salt(j:j+wh,i:i+wh,:);
w3=w1-w2;
end
k=k+1;
end