Creating 2D geometric shapes?

Hi, I need help here.
Basically, I am experimenting with this function called Hu Invariant Moment, starting off with a few geometric shapes (square, circle, triangle) created using (Windows) Paint. Those images were rotated, translated and scaled accordingly but for some strange reasons, when I saved those pictures, they didn't come out perfectly for me. What I meant by perfect was that I was expecting very thin contour lines (single pixel) for all the images, but that was not the case. By the way, the shapes are on white backgrounds.
So, is it possible to use MATLAB to create/draw out those shapes with the outlines as thin as possible?

댓글 수: 2

Sean de Wolski
Sean de Wolski 2011년 6월 22일
Can you post the images somewhere so we can see them?
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Jason
Jason 2011년 6월 22일
Hi Sean, thank you for you post. This is the results that I got when I run the code. Note: First image of each row is the original image, followed by the translated, rotated and scaled ones respectively.
http://www.flickr.com/photos/jokerzy89/5859633359/in/photostream

댓글을 달려면 로그인하십시오.

 채택된 답변

Sean de Wolski
Sean de Wolski 2011년 6월 22일

1 개 추천

I would guess the image actually isn't losing information, you're just zoomed out enough that it's not displaying everything (computer pixel resolution). Zoom in on one of the subplots and see if it looks better close up.
edit from comments
I = imread('ans622.jpg'); %your image
imshow(I(:,:,1),[0 1]); That's your original image - and hence why you're seeing the skeleton the way it is.
so what you want is
Ibw =(I(:,:,1)>200); %red channel greater than 200;
imtool(Ibw); %already 1px thick but you could run bwmorph for good measure or fun.

댓글 수: 15

Jason
Jason 2011년 6월 22일
Yes, that's what I did just now, zooming in to inspect the pixels, my guess is that nothing was lost. However, I feel that the lines are quite thick and thus not suitable for Moments calculation, any idea on how to thin those lines? FFT was proposed by my lecturer but I am not really cognizant of the process.
Here's the zoomed in pictures.
http://www.mathworks.com/matlabcentral/answers/10022-creating-2d-geometric-shapes
Note that for the last 2 pictures, around the vicinity of the lines, there are some greyish pixels, do I need to perform thresholding to get rid of those? Basically, I need pictures of type logical (0s and 1s).
Jason
Jason 2011년 6월 22일
Sorry here's the correct link: http://www.flickr.com/photos/jokerzy89/5860227992/sizes/l/in/photostream/
Sean de Wolski
Sean de Wolski 2011년 6월 22일
Yes, you can convert it to logical by using a threshold:
Ibw = I>some_value
or if you want anything non-black to show uo
Ibw = logical(I);
to thin the lines look at the 'skel' and 'thin' options in bwmorph. Can you give a little more information or a link for H.I.M.?
Jason
Jason 2011년 6월 22일
Thanks again, Sean.
Here's the link to H.I.M: http://en.wikipedia.org/wiki/Image_moment#Rotation_invariant_moments
So, I have got the M-Files for the functions ready. Since black = 0 and white = 1 for images(shapes) of type logical, when I read those images and run the HIM codes to calculate the respective moments, it should give me some values (contributed by the 1s from the lines). I feel that if the lines are not consistent in thickness, this would affect the results.
Sean de Wolski
Sean de Wolski 2011년 6월 22일
It probably would. So use:
I1px = bwmorph(Ibw,'skel',inf); %make the lines one pixel thick.
Jason
Jason 2011년 6월 22일
Sean, here's the outcome. Using the code you suggested right above, this is what I got. http://www.flickr.com/photos/jokerzy89/5860309284/sizes/l/in/photostream/
Sean de Wolski
Sean de Wolski 2011년 6월 22일
Huh? Did you binarize it so it was a logical image first?
I1px = bwmorph(logical(I),'skel',inf);
what does imtool(logical(I)) show?
Jason
Jason 2011년 6월 22일
Yes, I did, let's name the original image xyz.
I used xyz = logical(xyz), then I1px = bwmorph(xyz,'skel',inf), and got the results as shown on the link above.
In fact, imtool(logical(xyz)) yielded the same outcome.
http://www.flickr.com/photos/jokerzy89/5860401806/sizes/l/in/photostream/
Sean de Wolski
Sean de Wolski 2011년 6월 22일
can you post xyz before the logical operation by itself (a jpg file maybe)
Jason
Jason 2011년 6월 22일
http://www.flickr.com/photos/jokerzy89/5860423042/sizes/m/in/photostream/
In case you wish to download the file, just right click on the save it to your PC. Thanks!
Jason
Jason 2011년 6월 22일
Sean, if you don't mind, I still cannot see the difference between imshow(I); and imshow(I(:, :, 1),[0 1]);. I thought both should give the same output?
Sean de Wolski
Sean de Wolski 2011년 6월 22일
Save the image from the internet as I have done. Then read it in using imread.
Jason
Jason 2011년 6월 22일
I understand, but I am just curious as to why both commands display different output. When I used imshow(I);, I got a square which looks 'perfect', how come there was no skeleton?
Sean de Wolski
Sean de Wolski 2011년 6월 22일
because the other values are not visible due to the range that imshow is displaying. That's why I try to avoid it and use imtool. imtool offers you the adjust contrast tool on a visible histogram so you can see where/what values are and adjust the settings to make them visible.
(the little half white half black circle in imtool)
Jason
Jason 2011년 6월 22일
Awesome, thank you once again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2011년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by