compute The horizontal absolute difference value of a pixel [closed] - image

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
We have the test image with M rows and N columns as
f(x,y), for x∈ [1,M] and y∈ [1,N ]. The horizontal absolute
difference value of a pixel is defined by
D (x, y) = |f (x, y +1) − f (x, y −1)|.
need help in how to implement it in matlab

This will generate same size matrix, that you need:
mat1 = [zeros(2,size(f,2)); f];% adds 2 rows of zeros to begining
mat2 = [f;zeros(2,size(f,2))]; %adds 2 row of zeros to the end
Dd = mat1-mat2;
D = Dd(2:((size(Dd,1)-1)),:);%crop Dd matrix to size(f)

D = abs( f(1:end-1,:) - f(2:end,:) );
check out diff command as well. Note that D has 1 row less than f.

aux = abs(diff(f,[],2));
D = max(aux(:,1:end-1), aux(:,2:end));
For example: given
f = [3 5 6 4
2 5 4 3
8 9 3 1];
the result is
>> D
D =
2 2
3 1
6 6

Related

I want an algorithm to this problem. From a matrix m find the matrix r [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
matrix m:
1 2 3
4 5 6
7 8 9
output: (matrix r)
1 3 6
5 12 21
12 27 45
How we get the results is:
staring index = (0,0)
for example,
element at the (1,1) position of the result matrix would be,
r[1][1] = m[0][0] + m[0][1] + m[1][0] + m[1][1]
sum of the elements inside the red box:
element at the (2,1) position of the result matrix would be,
r[2][1] = matrix[0][0] + m[0][1] + m[1][0] + m[1][1] + m[2][0] + m[2][1]
sum of the elements inside the red box:
One important observation here is that for i > 0 and j > 0:
r[i][j] = m[i][j] + r[i-1][j] + r[i][j-1]
^ ^
When i == 0 or j == 0 then just drop the terms from the above expression that become invalid.
So:
r[0][0] = m[0][0]
And:
r[0][1] = m[0][1] + r[0][0]
If you continue with the first row from left to right and then the next rows in the same fashion, you'll always have the information needed to calculate r[i][j].

What could be the algorithm for ordered 9 digit problem? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Given any 3 digits N as an input,
we can only use digits from 1 to 9, in such a way that order never breaks and any repetition of number.
for example
If N = 150.
123 + 4 + 5 - 6 + 7 + 8 + 9 = 150
We can combine digits and insert '-' and '+' operations to get the desired N value.
Line up the numbers: 1 2 3 4 5 6 7 8 9.
There are 8 spaces between these numbers. Each space could be a '+' or a '-' or a blank (joining the digits together).
Thus, there are 3 ** 8 i.e., 6561 different possible combinations of operations you could use.
That's small enough to just try all of them in a loop and check which one works.
You can do it like this(this code is written by python):
N = 150
digit_from, digit_to = 1, 9 ### from 1 to 9 ###
def find(N, pos, equation, num, coff):
if pos > digit_to:
if N - coff * num == 0:
print(equation)
else:
find( N-coff*num, pos+1, equation+'+'+str(pos), pos, 1 ) ### plus ###
find( N-coff*num, pos+1, equation+'-'+str(pos), pos, -1 ) ### minus ###
find( N, pos+1, equation+str(pos), num*10+pos, coff ) ### blank ###
return
find( N, digit_from + 1, '150 = 1', digit_from, 1 )
Result(In case of N = 150 and digits between 1 to 9):
150 = 1+23+45-6+78+9
150 = 1+234+5+6-7-89
150 = 1-2+3-4+56+7+89
150 = 12+3+45-6+7+89
150 = 123+4+5-6+7+8+9
150 = 123+45+6-7-8-9
150 = 123-4-56+78+9
Thanks

find smallest number n in which have k relatively prime number in the interval [1,n] [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 6 years ago.
Improve this question
Euler Totient Function finds the number of numbers from 1 to n that are relatively prime to n.
For example--
phi(1) = 1
phi(2) = 1
phi(3) = 2
phi(4) = 2
phi(15) = 8
phi(16) = 8
phi(20) = 8
phi(24) = 8
. . . . . . . .
phi(n) = x
Here 15, 16, 20, 24 have 8 numbers between 1 to them that are relatively prime. But 15 is the smallest number with number of co-primes = 8.
How to find 15 if we input 8
Find a general algorithm for finding the smallest n such that phi(n) = x for an arbitrary x where x <= 2*10^9

Integer algorithm: find a mathematical function that fulfills given conditions [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
Given an integer x in the interval [1 .. 6], I am looking for two mathematical functions y1 and y2 so that:
y1(x) ∈ [1 .. 6], y2(x) ∈ [1 .. 6]
y1(x) ≠ y2(x) ≠ x
y1(x) and y2(x) are integers
I tried y1(x) = 7-x and y2(x) = (1+x)%6 where % is the remainder or modulo operation.
That solution does not work for x=6. I get y1(x) = y2(x) = 1, which does not fulfills the condition 2. Neither for x=3 and x=5.
Does anyone sees a working solution?
You can use for example:
y1=(x % 6) +1
y2=((x+1) % 6) +1
Functions as table:
x y1 y2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 1
6 1 2
Technically, y1=1+((x+1) %6) and y2=(1+(x+2) %6) both satisfy your request.
I guess though you were thinking about something with a unified distribution of some sort (which is usually the motivation for such attempts...).

Transposing a column with a line in a matrix [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 7 years ago.
Improve this question
We have this matrix of 4x4:
a b c d
e f g h
1 2 3 4
5 6 7 8
By transposing the matrix we get:
a e 1 5
b f 2 6
c g 3 7
d h 4 8
My question is:
What matrix do we get by "transposing column 2 with row 4?"
I need to understand the operation in itself, what does it imply/mean? I never thought of "transposing a column with a line".
AFAIK, It means you are to swap column 2 and row 4, instead of column 1 with row 1 and column2 with row 2 etc.
The code is basically the same as a full transposition, except you only have one column/row
Matrix transposition is a mathematical operation in which a matrix's rows become its columns. From a mathematical perspective, there's no real benefit to transposing only one row in a M x N matrix, but the code to transpose one row is not much different than transposing an entire matrix.
The matrix you get after the transposition would be:
a b 1 d
e f 2 h
c g 3 7
5 6 4 8

Resources