Please help how to translate the pseudocode into matlab code
3 次查看(过去 30 天)
显示 更早的评论
function FINDLOWERBASELINE(PP, threshold_value)
inside_region = 0 % Boolean value
for i = 1 -> length(PP) do
if PP(i) ≥ threshold_value and inside_region = 0 then % Entering a core zone
inside_region <- 1 % Create new core region
append [i,.] to core_regions % Higher baseline
else if PP(i) ≤ threshold_value and inside_region = 1
inside_region <- 0 % Leaving a core zone
core_regions[length(core_regions)][2] <- i % Lower baseline
end if
end for
if length(core_regions[length(core_regions) – 1]) = 1 then
append length(PP)-1 to core_regions[length(core_regions)-1]
end if
for k = 1 -> length(core_regions) do
add core_regions[k][2]-core_regions[k][1] to size_regions % Length of k-th core zone
end for
Let i_max the index of max(size_regions) % Index of larger core zone
return core_regions[i_max][2] % Lower baseline
end function
I(1∶m, 1∶n) % Text-line image with m lines and n columns
Define we wsmooth values
Local baseline estimation
Let baseline(j) = 0 (j = 1∶n)
for j = 1 -> n do
Iw = I(1∶m, j − we/2∶j + we/2)
PP = projectionprofile(Iw)
hist = histogram(PP)
threshold_value = Otsu_method(hist)
baseline(j) = FINDLOWERBASELINE (PP, threshold_value) % detail on findlowerbaseline function
end for
Baseline smoothing with gaussian filter
Let baseline_smoothed(j) = 0 (j = 1∶n)
Create gaussian_filter of width wsmooth and standard deviation σ=w_smooth/(4√2)
Baseline_smoothed = filter(baseline, gaussian_filter)
Correction
Let Icorr(1:m, 1:n) % Corrected image
baselinemean = 1/n ∑_(i=1)^n▒〖baseline〗_smooth 1 % Mean of local baseline
for j = 1 -> n do
for i = 1 -> m do
if I(i,j) is foreground pixel then
Let Δ = baseline_smoothed(j) − baselinemean % Vertical shift for correction
if 0 < i + Δ < m then
Icorr(i + Δ, j) <- I(i,j)
end if
end if
end for
end for
1 个评论
Image Analyst
2016-7-13
Don't double space code. Instead highlight it and click the {}Code button. See step by step instructions: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
回答(1 个)
Image Analyst
2016-7-13
Go down one line at a time replacing bad syntax with correct syntax, like
- "and" with "&&",
- "else if" with "elseif",
- "<-" with "=",
- "->" with ":", and so on.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!