image dividing, padding, regions

How to divide an image up into say 10x10 regions and account for padding (an integer number of regions does not fit in the image)
I have tried complicated convolution methods, and now want to try a more simplified approach. The aim is to then locally threshold each image for SNR calculations
This was my attempt:
n=10; %regions in each dimension
[x,y]=size(ROI)
nx=floor(x/n)
ny=floor(y/n)
xGrid=1:(nx+1):10*nx
yGrid=1:(ny+1):10*ny
[X,Y]=meshgrid(xGrid,yGrid)
mesh(X,Y)

 採用された回答

Image Analyst
Image Analyst 2015 年 1 月 12 日

0 投票

Attached is a demo where I use local thresholding to correct a shaded document to prepare it for OCR.

3 件のコメント

Jason
Jason 2015 年 1 月 12 日
編集済み: Jason 2015 年 1 月 12 日
Thanks IA. I've also come across another example you have written: In particular to split the image up into 4:
[rows columns] = size(ROI);
% Taking care to handle odd-size dimensions:
col1 = 1;
col2 = floor(columns/2);
col3 = col2 + 1;
row1 = 1;
row2 = floor(rows/2);
row3 = row2 + 1;
% Now crop
upperLeft = imcrop(ROI, [col1 row1 col2 row2]);
upperRight = imcrop(ROI, [col3 row1 columns - col2 row2]);
lowerLeft = imcrop(ROI, [col1 row3 col2 row2]);
lowerRight = imcrop(ROI, [col3 row3 columns - col2 rows - row2]);
% Display the images.
subplot(2, 3, 2);
imshow(upperLeft);
subplot(2, 3, 3);
imshow(upperRight);
subplot(2, 3, 5);
imshow(lowerLeft);
subplot(2, 3, 6);
imshow(lowerRight);
If I want to split into 8 to see if local thresholding is more effective for smaller ROI's, do I handle fractional values by using floor? How do draw ontop of the raw image a line grid representing how the image is being split up?
Also how are boundaries between the subregions handled, are there any pixels that are ignored?
Thanks
Image Analyst
Image Analyst 2015 年 1 月 12 日
Try this:
rows = 1234 % Whatever....
tiles = 8 % Number of tiles or chunks you want it divide up into.
% Find out where the dividing lines are. This may be a fractional value.
startingRows = linspace(1, rows, tiles+1)
% Now get the starting integer rows.
startingRows = int32(startingRows(1:end-1))
% Get the ending rows.
endingRows = [startingRows(2:end)-1, rows]
In the command window, see the proper starting and ending rows for each chunk:
startingRows =
Columns 1 through 7
1 155.125 309.25 463.375 617.5 771.625 925.75
Columns 8 through 9
1079.875 1234
startingRows =
1 155 309 463 618 772 926 1080
endingRows =
154 308 462 617 771 925 1079 1234
Jason
Jason 2015 年 1 月 13 日
編集済み: Jason 2015 年 1 月 13 日
Many thanks, I've taken your suggestion and almost got my solution. I managed to add the dividing lines onto the image, and I have attempted to add each tile to an image stack so I can process further: Its the adding to image stack that I can't understand why my code isn't working.
[rows,cols]=size(ROI) % ROI is my Image
tiles = 4 % Number of tiles or chunks you want it divide up into.
% Find out where the dividing lines are. This may be a fractional value.
startingRows = linspace(1, rows, tiles+1)
startingCols = linspace(1, cols, tiles+1)
% Now get the starting integer rows / cols.
startingRows = int32(startingRows(1:end-1))
startingCols = int32(startingCols(1:end-1))
% Get the ending rows.
endingRows = [startingRows(2:end)-1, rows]
endingCols = [startingCols(2:end)-1, cols]
%Determine number of pixels in each tile;
nx=endingRows(1)-startingRows(1)
ny=endingCols(1)-startingCols(1)
%PreDefine Image stack (IM)
nimages=tiles*tiles
IM = zeros(nx, ny, nimages, class(ROI));
subplot(2,4,[1,2,5,6])
hold on
for i=1:nimages
plot([startingRows(i),startingRows(i)],[0,cols],'y-');
plot([0,rows],[startingCols(i),startingCols(i)],'y-');
IM(:,:,i)=ROI(startingRows(i):endingRows(i),startingCols(i),endingCols(i));
%IM(:,:,i)=ROI(1:25,1:25);
end
hold off;
subplot(2,4,3)
imshow(IM(:,:,1))

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2015 年 1 月 12 日

編集済み:

2015 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by