![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174022/image.png)
Scan through an image to detect the mid points of 2 grey regions
조회 수: 2 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148131/image.png)
Hi above is an image that Im trying to process. Im looking to automatically plot 2 lines through the middle of the 2 grey regions, i.e. scan up through the rows of the image and detect the end of the darker region then plot the midpoint, scan up through the image again and detect the lighter grey region and then plot the midpoint in that region. The reason Im looking to do this is that the beginning and end of these grey regions vary over images, with an automatic solution to plotting the middle row or midpoint of these segments will allow me to calculate further statistical analysis on the specified rows to give all the pixels in the image the same overall or average value.
댓글 수: 0
채택된 답변
Ashish Uthama
2015년 3월 19일
편집: Ashish Uthama
2015년 3월 19일
See if this gives you any ideas:
im = imread('/tmp/t.png');
imtool(im);
% RGB? gray scale
im = rgb2gray(im);
figure;
plot(im);
%%150 looks like a good threshold
imt = im>150;
imshow(imt,[]);
%%Clean it up (remove single pixel white or dark spots)
imtc = bwmorph(imt, 'clean');
imtc = ~bwmorph(~imtc,'clean');
imshowpair(imt, imtc)
%%Image looks fairly horizontal, process one vertical scan line at a time
lineImg = false(size(imtc));
for c = 1:size(imtc,2)
col = imtc(:,c);
transitions = diff(col);
transitionPoints = find(transitions);
if(numel(transitionPoints)~=2)
disp(['Skipping col ' num2str(c) '. Found multiple transitions']);
continue;
end
midpoint1 = round(mean(transitionPoints));
midpoint2 = round(mean([transitionPoints(2) numel(col)]));
lineImg(midpoint1, c) = true;
lineImg(midpoint2, c) = true;
end
imshowpair(im, lineImg);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174022/image.png)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!