Image segmentation/blocking and get value from each block

조회 수: 5 (최근 30일)
sazzad hossen
sazzad hossen 2014년 4월 17일
답변: PRABIRA KUMAR SETHY 2019년 3월 11일
First image is my input image i want to make 1)first divided(segment) my image into M*N block (like Second pic) 2) the i want to calculate(percentage of black and white color) from each block 3) then each block separate based on a threshold value of black or while percentage
i am new in image processing please give me a details explain, how can i solve my problem
Thanks in advance

채택된 답변

Image Analyst
Image Analyst 2014년 4월 17일
Have you done step 1 yet? It look like it.
Then threshold the image with a fixed threshold that is just above the gray level of the chassis.
binaryImage = grayImage > threshold;
See the interactive thresholding utility/tool in my my File Exchange Also run the Image Segmentation Tutorial there.
Next you need to scan the blocks in your image. Assuming you have the rows and columns of the red lines, do something like this:
for xBlockIndex = 1 : length(columns)-1
col1 = columns(xBlockIndex);
col2 = columns(xBlockIndex+ 1) - 1;
for yBlockIndex = 1 : length(rows)-1
row1 = rows(yBlockIndex);
row2 = rows(yBlockIndex+1)-1;
% Extract sub image
subImage = grayImage(row1:row2, col1:col2);
% Extract mask sub image
subImageMask = binaryImage(row1:row2, col1:col2);
% Compute mean for pixel above the threshold.
meanGrayLevels(yBlockIndex, xBlockIndex) = mean(subImage(subImageMask));
end
end
  댓글 수: 10
sazzad hossen
sazzad hossen 2014년 4월 23일
Dear Image Analyst,
Thanks a lot for your effort, you really do a great job for me, i am trying to make my code based on your coding.
Thanks again.
abhishek
abhishek 2014년 7월 1일
Thnx a lot sir. THANX A LOT.

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

추가 답변 (1개)

PRABIRA KUMAR SETHY
PRABIRA KUMAR SETHY 2019년 3월 11일
Dear Rsearcher
I have a rice panicle iamge. Then I separate to number of block, which size is same as the size of grain. This much I completed.Code attached. Now I want to detect the defected grain (blackish) in each block by applying some kind of thresholding operation. Then show the blocks which contain the defected grain. Then count these blocks. kindly help me.
.panicle1.jpg

Community Treasure Hunt

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

Start Hunting!

Translated by