이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi,
I want to draw grid on an image and I want to count the number of grid boxes which cover an object in that image. Some regions of that object intersect the grid. How can I count those intersect grids as well as inside of that object.?
Experts kindly get me the solution.
Regards Dams
채택된 답변
Image Analyst
2013년 5월 11일
Damodara:
If you draw C lines along the columns (vertically), this will split the image into (C+1) vertical strips. If you draw R lines along the rows (horizontally), this will split the image into (R+1) horizontal strips. You will then have (C+1)*(R+1) boxes in the grid. You will have C*R intersections, where the vertical and horizontal lines intersect.
If you have a binary image then you need to make a mask of the lines and multiply it or assign the binary image to be false there. Then call bwlabel to get the number of parts you chopped your object into.
[labeledImage, numberOfPieces] = bwlabel(binaryImage);
Of course that depends on where you drew your lines and will have a problem if any of the lines overlap a 1 pixel wide part. Please run this demo I made specially for you:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Synthesize an image.
grayImage = peaks(400);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
fh = figure;
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Binarize the image by thresholding it.
binaryImage = grayImage > 2.1;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Make mask
columnSplitters = 16:32:columns;
rowSplitters = 16:32:rows;
splitBinaryImage = binaryImage; % Initialize.
splitBinaryImage(:, columnSplitters) = false;
splitBinaryImage(rowSplitters, :) = false;
% Display the image.
subplot(2, 2, 3);
imshow(splitBinaryImage, []);
title('Split Binary Image', 'FontSize', fontSize);
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(splitBinaryImage, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 2, 4);
imshow(coloredLabelsImage);
caption = sprintf('The number of pieces = %d', numberOfBlobs)
title(caption, 'FontSize', fontSize);
message = sprintf('Done with Image Analyst demo.\nThe number of pieces = %d', numberOfBlobs);
uiwait(helpdlg(message));
close(fh); % Close down the figure

댓글 수: 12
P.S. Note that all the slicing lines are not shown in the lower left image due to subsampling (shrinking) of the image.
Damodara
2013년 5월 12일
편집: Image Analyst
2013년 5월 12일
Thanks but here if you reduce row and column splitters to one it will not give any count. And even mask lines take some pixels so count will be wrong if you consider more lines. My code as here. Kindly check this and how can I count these pieces.? Please help me.
myFolder =uigetdir;
%....GET INPUT DIRCTORY......
filePattern = fullfile(myFolder, '*.png');
pngFiles = dir(filePattern);
for i = 1:length(pngFiles)
baseFileName = pngFiles(i).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
binaryImage(:,:,i)=imread(fullFileName);
imagesc(binaryImage);
colormap(gray)
[nX,nY,nZ]=size(binaryImage);
nSeg=max(nX,nY);
set(gca,'xtick',linspace(0,nY,nSeg+1),'xticklabel',[],...
'xgrid','on','xcolor','K',...
'ytick',linspace(0,nX,nSeg+1),'ytickLabel',[],...
'ygrid','on','ycolor','K',...
'gridLineStyle','-','linewidth',1)
end
Regards Dams
But, unlike my code, your code doesn't do anything. It just reads in images, and even then it requires that they all be the same size. Did you forget to adapt my code and paste it in? And I warned you about the line taking up a pixel and thus would need to be adapted some if you expect to have one pixel wide regions. And of course, you need to specify exactly what rows and columns you want to split the image on - recall I said it depends on where you draw your lines. I assume you know that, and know that I just made some arbitrary decisions on that, but it looks like I better make that crystal clear.
Yes I have tried your code. Its good what I expected. But again I am facing bit problem how can I get one pixel regions from your code.?Suppose an object has 756 pixels in an image. If I split that object to one pixel regions then it has to give 756. Is there any way to split without considering mask lines because it takes a pixel to draw a line as like mentioned in above code just draw grid and how many regions are there .?
Regards Dams
I thought you wanted grid boxes over the object - that's what you said. If you want individual pixels, then the image is already in that form. Each element is a single pixel.
If you have an object, you can get the individual pixel coordinates using the PixelList measurement returned by regionprops(). You can get the pixel values using the PixelValues measurement returned by regionprops().
Yes, I wanted grid boxes over the object and count number of grid boxes which cover only that object. Even I wanted to increase grid size from one pixel to size of that image that is where I stuck up. I can increase grid size in loop but how to count which covers only that object. ?
I don't understand what you are asking. Time for you to upload a screenshot.
Hi, How can I upload my screenshot here. ?
Regards Dams
Activate your window, type alt-printscreen, go to http://snag.gy and type control-v. Then tell me the URL that you see.
Hi,
How can count these grid boxes which cover that object. I wanted to count for different grid size. http://snag.gy/VOThM.jpg
Regards Dams
How is that different than what I did? And your boxes are not one pixel wide. The grid lines are, but the boxes are not -they're wider than that, just like I had. What's the use of chopping your object up like this anyway?
Hi,
Here grid size is not one pixel. Have tried my code which i posted.?I have given an example. I want to use it for fractal dimension. Regards Dams
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
