Hello!
I would like to process an image like all steps in this picture in Octave.
I wonder how I can add to images together to get a picture like (c) of (f)?
My code so far is:
I = imread('343a.tif');
subplot(2,2,1);imshow(I);title('Original Image');
I = im2double (I);
H = fspecial('log', 11,1.5);
Laplacian = imfilter(I,H,'replicate');
subplot(2,2,2);imshow(Laplacian, []);title('Laplacian Image');
H = fspecial('sobel');
Edge = imfilter(I,H,'replicate');
subplot(2,2,4);imshow(Edge);title('Sobel Image');
Would be very thankful for help or suggestions! :)
Best regards!
You add images using the + operator and multiply them using the .* operator:
c = a + b;
f = c .* e;
Yes, it's really that simple! :)
Related
to practice Wiener deconvolution, I'm trying to perform a simple deconvolution:
def div(img1 ,img2):
res = np.zeros(img2.shape, dtype = 'complex_')
for i in range (img2.shape[0]):
for j in range (img2.shape[0]):
if (np.abs(img2[i][j]) > 0.001):
res[i][j] = 1 / (img2[i][j])
else:
res[i][j] = 0.001
return res
filtre = np.asarray([[1,1,1],
[1,1,1],
[1,1,1]]) * 1/9
filtre_freq = fft2(filtre)
v = signal.convolve(img, filtre)
F = div(1,(filtre_freq))
f = ifft2(F)
res = signal.convolve(v, f)
I am trying to compute the inverse filter in the frequency domain, pass it to the spatial domain and do the convolution with the inverse filter. On paper it's pretty simple, even if I have to manage the divisions by 0 without really knowing how to do it.
But my results seem really inconsistent:
If anyone can enlighten me on this ... Thanks in advance and have a great evening.
I'm doing an experiment using face images in PyTorch framework. The input x is the given face image of size 5 * 5 (height * width) and there are 192 channels.
Objective: To obtain patches of x of patch_size(given as argument).
I have obtained the required result with the help of two for loops. But I want a better-vectorized solution so that the computation cost will be very less than using two for loops.
Used: PyTorch 0.4.1, (12 GB) Nvidia TitanX GPU.
The following is my implementation using two for loops
def extractpatches( x, patch_size): # x is bsx192x5x5
patches = x.unfold( 2, patch_size , 1).unfold(3,patch_size,1)
bs,c,pi,pj, _, _ = patches.size() #bs,192,
cnt = 0
p = torch.empty((bs,pi*pj,c,patch_size,patch_size)).to(device)
s = torch.empty((bs,pi*pj, c*patch_size*patch_size)).to(device)
//Want a vectorized method instead of two for loops below
for i in range(pi):
for j in range(pj):
p[:,cnt,:,:,:] = patches[:,:,i,j,:,:]
s[:,cnt,:] = p[:,cnt,:,:,:].view(-1,c*patch_size*patch_size)
cnt = cnt+1
return s
Thanks for your help in advance.
I think you can try this as following. I used some parts of your code for my experiment and it worked for me. Here l and f are the lists of tensor patches
l = [patches[:,:,int(i/pi),i%pi,:,:] for i in range(pi * pi)]
f = [l[i].contiguous().view(-1,c*patch_size*patch_size) for i in range(pi * pi)]
You can verify the above code using toy input values.
Thanks.
I am a newbie in the field of CV and IP. I was writing the HoughTransform algorithm for finding line.I am not getting what is wrong with this code in which i m trying to find the accumulator array
numRowsInBW = size(BW,1);
numColsInBW = size(BW,2);
%length of the diagonal of image
D = sqrt((numRowsInBW - 1)^2 + (numColsInBW - 1)^2);
%number of rows in the accumulator array
nrho = 2*(ceil(D/rhoStep)) + 1;
%number of cols in the accumulator array
ntheta = length(theta);
H = zeros(nrho,ntheta);
%this means the particular pixle is white
%i.e the edge pixle
[allrows allcols] = find(BW == 1);
for i = (1 : size(allrows))
y = allrows(i);
x = allcols(i);
for th = (1 : 180)
d = floor(x*cos(th) - y*sin(th));
H(d+floor(nrho/2),th) += 1;
end
end
I m applying this for a simple image
I m getting this result
But this is expected
I am not able to find the mistake.Please help me.Thanks in advance.
There are several issues with your code. The main issue is here:
ntheta = length(theta);
% ...
for i = (1 : size(allrows))
% ...
for th = (1 : 180)
d = floor(x*cos(th) - y*sin(th));
% ...
th seems to be an angle in degrees. cos(th) is meaningless. Instead, use cosd and sind.
Another issue is that th iterates from 1 to 180, but there is no guarantee that ntheta is 180. So, loop as follows instead:
for i = 1 : size(allrows)
% ...
for j = 1 : numel(theta)
th = theta(j);
% ...
and use th as the angle, and j as the index into H.
Finally, given your image and your expected output, you should apply some edge detection first (Canny, for example). Maybe you already did this?
I am getting different results between the below iterative way and a simple vector way in octave(simple regression). What am I doing wrong in the iterative way ?
Iterative version
sum_val = 0;
for m_val = 1:m,
h = X(m_val,:) * theta;
err_sq = power((h - y(m_val)),2);
sum_val = sum_val + err_sq;
end;
J = (1/2*m)*sum_val;
Vector way:
J = (1/(2*m))*sum(power((X*theta - y),2));
In MATLAB, and so I presume in Octave as well, 1/2*m is not the same as 1/(2*m). This is your source of error.
How to solve the below recurrence relation?
T(n) = 2T(root(n)) + logn/loglogn if n > 4
T(n) = 1 if n <= 4
Preferably by master theorem otherwise by any method.
I know Master Theorem fails,But is there any extension for these type of problems?
Can you guide me any stuff for solving complex relation like above?
I think this should work :
if n = 2^m and T(2^m) = s(m) then
logn = m , loglogn = logm ;
s(m) = 2*s(m/2) + m/logm ;
now solving the above equation is our problem
now you can not use the master theorem for solving this , so you have to use other methods like expanding this equation by writing s(m/2) and s(m/4) and then you might solve this problem , and after doing that you change your parameters to n again .
According to me
if n = 2^m and T(2^m) = s(m) then
logn = m , loglogn = logm ;
s(m) = 2*s(m/2) + m/logm ;