How to design convolution kernals?

25 visualizzazioni (ultimi 30 giorni)
Jiby
Jiby il 13 Ott 2022
Commentato: Jiby il 15 Ott 2022
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 Commenti
Jiby
Jiby il 15 Ott 2022
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
Jiby
Jiby il 15 Ott 2022
I am working on others @DGM
I will surely get back with answers with those hints provided.
Thanks a lot..

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 15 Ott 2022
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 Commenti
Image Analyst
Image Analyst il 15 Ott 2022
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".
Jiby
Jiby il 15 Ott 2022
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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by