How to design convolution kernals?

Design convolution kernels
i. Translating image
ii. Invert the image
iii. Rectify the image
iv. Subtract from each pixel the value of the mean of the contiguous surrounding pixels.
v. Highlight vertical edges by taking a derivative in the horizontal direction only.
vi. Embossing effect below and to the right of image features.
vii. Flip the image left to right.
viii. Make a single kernel to cascade operations i) and ii) above.
Invent and implement and algorithm to determine the amount and direction of shift between the images in ct.jpg and ctshift.jpg.
Please provide a listing of your code, and the shift in both i and j.

6 个评论

This is one example of how I make a QD low-pass filtering kernel:
fK1 = [.25 .75 1 .75 .25];
fK = conv2(fK/3,fK'/3,'full');
That should illustrate that step in your homework.
HTH
Could you please make it more clear @Bjorn Gustavsson
Sure use that convolution-kernel on your homework assignment image and see what it produces. Then modify it somewhat and see what a convolution with that modified kernel leads to. Then read the textbook and lecture notes, think and ponder.
To increase your chances to get detailed code solving your homework tast you should heed the advice by Steven Lords comment here.
Look up a Prewitt or Roberts filter, figure out why it does what it does. Can it be used to answer one of these?
What does fk = [0 0 0 0 1] do?
Consider fk = [0 0 0; 0 1 0; 0 0 0] - [1 1 1; 1 0 1; 1 1 1]/8. Which case does that satisfy? Do you see why?
Remember that convolution is associative; that should provide a means to answer #8.
Note that image()/imagesc()/imshow() will truncate values if they're outside the expected display range, so don't let that confuse you.
Thanks a lot @DGM
I could understand subtraction and mean kernel (iv) question now.
clf reset
ct=imread('ct.jpeg')
close all hidden
colormap('gray')
h6 = [-1/8,-1/8,-1/8;
-1/8,1,-1/8;
-1/8,-1/8,-1/8] %[0 0 0; 0 1 0; 0 0 0] - [1 1 1; 1 0 1; 1 1 1]/8
subplot(2,2,1), imagesc(ct);
title('Raw Image'), xlabel i, ylabel j, colorbar
subplot(2,2,2), imagesc(h6);
title('Subtraction & mean Kernel'), xlabel i, ylabel j, colorbar
subplot(2,2,4), imagesc(conv2(ct,h6));
title('Convolved Sub Result'), xlabel i, ylabel j, colorbar
I am working on others @DGM
I will surely get back with answers with those hints provided.
Thanks a lot..

请先登录,再进行评论。

 采纳的回答

Image Analyst
Image Analyst 2022-10-15
Not sure what invert and rectify means. Does it mean spatially or in intensity?
For translate just have a 1-@ or 2-D kernel of a delta function, in other words an array that is all zeros except there is a 1 NOT at the very center of the array but offset some distance from it. The distance away from the center specifies the translation and the direction determines the direction of the shift.
For iv, you can get the mean of all pixels in a 3x3 window with ones(3)/9. To get the mean of the surrounding pixels it would be 1's just in the 8 pixels in the ring (don't include the center) but then you have to divide by 8 instead of 9. So the kernel to subtract that from 1 would be a 3x3 window with 1 in the middle minus that kernel with 1/8's in it.
Remember to cast your image to double before you pass it in to conv2. That's not necessary if you use imfilter.

4 个评论

Thank you @imageanalyst
I could understand and execute translation function using this. As the image movement towards down and left, I defined it at the corner point of the matrix.
What is the difference between Inversion and rectification by spatial or intensity?
Also, what is the importance of the data type as uint8 or double and what impact do it have on functions such as imfilter
If I recall from a prior version of this question, "rectification" implies the absolute value of the image.
For my own interpretation, "invert" is synonymous with "complement"
outpict = whitevalue - inpict;
however, I have a feeling that the assignment simply means
outpict = -inpict;
I really don't know.
I don't know how to either
  1. invert the intensity of pixels, or
  2. invert/flip the image right-to-left, or top-to-bottom
using just convolution alone. Of course you can flip the image spatially using fliplr or flipud, and you can invert the intensity just by subtracting the image from a constant, such as the white value of 255 for a uint8 image or 65535 for a 16 bit image.
Normally for some kernel, in general, the output value will be a floating point number (unless all the kernel numbers were integers). So, for whatever reason conv2 won't cast unsigned integer image variables into double -- you have to do that yourself while or before calling conv2. With imfilter it probably does that for you internally. Then, imfilter casts it back to the original unsigned integer class upon returning the result to you. Also, imfilter does not flip the kernel like convolution does, so it's more like a correlation than a convolution because of that. But correlation and convolution are the same except that convolution flips the kernel. There are theoretical, mathematical reasons for that. Also, imfilter has a lot more choices for how to handle the edge situation, like when the sliding window is in a location where part of the window is "off the image".
As mentioned by @DGM & @Image Analyst
I did translation using
ct=imread('ct.jpeg')
close all hidden
colormap('gray')
h2=zeros([200 100]);
h2(200,1)=1;
subplot(2,2,1), imagesc(ct);
title('Raw Image'), xlabel i, ylabel j, colorbar
subplot(2,2,2), imagesc(h2);
title('200x100 Shift Kernel'), xlabel i, ylabel j, colorbar
subplot(2,2,3), imagesc(conv2(ct,h2));
title('Convolution Result'), xlabel i, ylabel j, colorbar
I did inversion using the negative value
ct=imread('ct.jpeg')
close all hidden
colormap('gray')
h1=-1
subplot(2,2,1), imagesc(ct);
title('Raw Image'), xlabel i, ylabel j, colorbar
subplot(2,2,2), imagesc(h1);
title('Image Reversal Kernel'), xlabel i, ylabel j, colorbar
subplot(2,2,3), imagesc(conv2(ct,h1));
title('Convolution Result'), xlabel i, ylabel j, colorbar

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by