phot_stereo_braille

* Example program to demonstrate photometric stereo
* Input are 6 images taken from braille with light coming
* from different orientations and angles. After the height
* extraction, the dots are extracted and grouped to characters
dev_close_window ()
dev_update_off ()
read_image (Image, 'photometric_stereo/embossed_01')
get_image_size (Image, WindowWidth, WindowHeight)
dev_open_window_fit_size (0, 0, WindowWidth, WindowHeight, WindowWidth * 0.6, WindowHeight * 0.6, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, 'Extract braille characters using\nphotometric stereo. For this approach\nsix different light setups were used.', 'window', 10, 10, 'black', 'true')
stop ()

* Show input images (illuminated differently)
FileNames := []
for I := 1 to 6 by 1
    FileNames := [FileNames,'photometric_stereo/embossed_' + I$'.2']
endfor
read_image (Images, FileNames)
count_obj (Images, NumImages)
for I := 1 to NumImages by 1
    select_obj (Images, ObjectSelected, I)
    dev_display (ObjectSelected)
    wait_seconds (0.5)
endfor

* Apply photometric stereo to determine the height field
photometric_stereo (Images, Height, Gradient, Albedo, [70,50,70,50,70,50], [0,0,90,90,180,180], 'all', 'rft_cyclic', [], [])
mean_image (Height, ImageMean, 61, 61)
sub_image (Height, ImageMean, ImageSub, 1, 0)
dev_display (ImageSub)
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, 'Reconstruct the height field\napplying photometric stereo', 'window', 10, 10, 'black', 'true')
stop ()
dev_display (Image)

* Shade a height field
disp_message (WindowHandle, 'Shade the height field\nof the braille dots', 'window', 10, 10, 'black', 'true')
wait_seconds (2)
for I := 0 to 360 by 10
    shade_height_field (ImageSub, ShadedFace, 45, I, 1, 0, 'false')
    dev_display (ShadedFace)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

* Segment brailles dots
threshold (ImageSub, Region, 0.35, 1000)
dev_set_draw ('margin')
dev_set_line_width (4)
dev_set_color ('green')
dev_display (Image)
dev_display (Region)
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, 'Segment single dots', 'window', 10, 10, 'black', 'true')
stop ()

* Group brailles dots to characters
closing_rectangle1 (Region, RegionClosing, 200, 60)
connection (RegionClosing, ConnectedRegions)
count_obj (ConnectedRegions, Number)
dev_display (Image)
dev_set_colored (12)
for I := 1 to Number by 1
    select_obj (ConnectedRegions, ObjectSelected, I)
    intersection (ObjectSelected, Region, RegionIntersection)
    partition_dynamic (RegionIntersection, Partitioned, 135, 20)
    dev_display (Partitioned)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, 'Finally, group the dots that describe\nindividual braille characters', 'window', 10, 10, 'black', 'true')
stop ()

* Another way is to use the mean curvature to extract the dots. Note that the Gradient must be calulated only.
* This version is faster because no height field must be calculated.
photometric_stereo (Images, Height1, Gradient1, Albedo1, [70,50,70,50,70,50], [0,0,90,90,180,180], 'gradient', 'rft_cyclic', [], [])
derivate_vector_field (Gradient1, Result, 1, 'mean_curvature')
dev_display (Result)
disp_message (WindowHandle, 'Alternative Solution: Use gauss curvature of gradient image\nto segment the dots', 'window', 10, 10, 'black', 'true')
stop ()
threshold (Result, Region, -10, 0)
connection (Region, ConnectedRegions1)
fill_up (ConnectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions1, ['area','circularity'], 'and', [150,0.8], [99999,1])
count_obj (SelectedRegions1, Number)
union1 (SelectedRegions1, RegionUnion)
closing_rectangle1 (RegionUnion, RegionClosing1, 200, 60)
connection (RegionClosing1, ConnectedRegions)
count_obj (ConnectedRegions, Number)
dev_display (Image)
dev_set_colored (12)
for I := 1 to Number by 1
    select_obj (ConnectedRegions, ObjectSelected, I)
    intersection (ObjectSelected, RegionUnion, RegionIntersection)
    partition_dynamic (RegionIntersection, Partitioned, 135, 20)
    dev_display (Partitioned)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, 'Finally, group the dots that describe\nindividual braille characters', 'window', 10, 10, 'black', 'true')

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

electrical1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值