Continuous line drawing from halftoned image
Show older comments
Hello, I would like to make one continuous line through all points in a binary image that I have halftoned. I also made a structuring element with strel('line') and the output looks good except I want a continuous line, so if it's easier to make a continuous line out of that image than just the purely halftoned image, that is fine too.
Things I have tried:
- using two line structuring elements and the 'imclose' filter twice, one line at 45 degrees and the next at 135 (so they are perpendicular structuring elements and I'm proccessing the image twice to try to create overlap)
- using the 'imdilate' filter
- researching nearest neighbor searches, but haven't found anything that I can make sense out of at my level of knowledge
- making a 'sine wave' function that varies its amplitude with the 'brightness' of the image - so block processing an area and going through and transforming the sine wave function to look brighter or darker depending on region of image being on average brighter or darker in that block. I would love to do this but I'm stuck on how to even plot the output. I have a binary image so I think I understand that I would evaluate the 'brightness' by taking average of a block and then I have a 0 - 255 value representing the level of 'brightness'. At that point I understand I'd need some math to phase shift the sine wave if I adjusted the frequency, but going a simpler route I'd like to just use amplitude modulation and line up the period of the sine wave with the amount of actual pixels (so period*n = width of block in pixels)in the block I'm processing so that I don't have to do this? Then I would just make a border to connect every wave.
I know the sine wave thing is out there but if my level of understanding is just connecting the lines then that's perfectly fine, haha.
I'll include my code so far below as well as three output images, the halftoned image, the 'line drawing' images @45 degrees and 0 degrees.
Note: You'll see I have made my code so that it automatically crops the image to square so that the matrix manipulations are easier.
im = imread('FaceRGB.jpg');
im=im2double(im);
sizes = size(im);
r = sizes(1);
c = sizes(2);
if r<c
N = r;
else
N = c;
end
targetsize = [N, N];
re = centerCropWindow2d(sizes,targetsize);
squareimage = imcrop(im, re);
im = rgb2gray(squareimage);
im=im2double(im);
im = imresize(im, 0.125);
im = imresize(im, 8);
[s1, s2]=size(im);
MAT=[24 10 12 26 35 47 49 37;
08 00 02 14 45 59 61 51;
22 06 04 16 43 57 63 53;
30 20 18 28 33 41 55 39;
34 46 48 36 25 11 13 27;
44 58 60 50 09 01 03 15;
42 56 62 52 23 07 05 17;
32 40 54 38 31 21 19 29;]/64;
r = (s1/8);
c = (s2/8);
mask=repmat(MAT,[r c]);
Halftone =im>mask;
image = imshow(Halftone);
imwrite(Halftone, 'face_halftone.tiff');
se = strel('line', 10, 45);
image2 = imclose(Halftone, se);
figure, imshow(image2)
imwrite(image2, 'face_lines.tiff');
1 Comment
yanqi liu
on 17 Dec 2021
which is FaceRGB.jpg? is it as Halftoned_Image.jpg?
Accepted Answer
More Answers (0)
Categories
Find more on Computer Vision Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!