MATLAB: Draw 1 inch Square on Image

imageimage analysisimage processingimage segmentationMATLAB

Hello,
How can I draw 1 inch square on my image and wanted to find number of grains present in that square ? Attached is my Image for reference. In attached RefImage_WithSquare, wanted to count no. of grains present in that square grains on boundary line must be considered as partial grain. Just as we consider in ASTM Grain Analysis.

Best Answer

If your resolution is 96 dpi, use the rectangle() function with a width and height of 96:
imshow('untitled.png');
axis on;
hold on;
impixelinfo(); % Show x, y, RGB as you mouse around over image.
xLeft = 85; % Wherever you want.
yTop = 32;
rectangle('Position', [xLeft, yTop, 96, 96], 'EdgeColor', 'r', 'LineWidth', 2);