how to creat a rectangular 100*100 in center of an image?
3 ビュー (過去 30 日間)
古いコメントを表示
i need to creat a rectangular 100*100 in center of an image? i used shapeInserter = vision.ShapeInserter but it`s not what i need. this function creats rectang. on image but i need a rectang. in center of image
0 件のコメント
採用された回答
Image Analyst
2013 年 4 月 17 日
imageArray(row1:row2, col1:col2) = grayValue; % grayValue can be any number.
row1 is half the height minus 50 pixels, col2 is half the width plus 50 pixels, and so on for other parameters.
0 件のコメント
その他の回答 (1 件)
DGM
2022 年 10 月 25 日
編集済み: DGM
2022 年 10 月 25 日
If you want to create a rectangular region of a fixed geometry:
% get a grayscale image
inpict = imread('cameraman.tif');
% specify the new color (gray, uint8-scale)
newcolor = 128;
% create a rectangle of fixed geometry
rectsz = [100 150]; % specify a box geometry [h w]
sz = [size(inpict,1) size(inpict,2)];
hw = rectsz/2;
rows = round(sz(1)/2-hw(1)):round(sz(1)/2+hw(1));
cols = round(sz(2)/2-hw(2)):round(sz(2)/2+hw(2));
rows = min(max(rows,1),sz(1));
cols = min(max(cols,1),sz(1));
% assign a value to the ROI
inpict(rows,cols,:) = newcolor;
imshow(inpict)
If you want to create a rectangular region that's proportional to the image geometry:
% get a grayscale image
inpict = imread('cameraman.tif');
% specify the new color (gray, uint8-scale)
newcolor = 128;
% pick a rectangular region that's proportional to the image geometry
w = [0.4 0.6]; % specify a box proportions [h w]
sz = [size(inpict,1) size(inpict,2)];
hw = w.*sz/2;
rows = round(sz(1)/2-hw(1)):round(sz(1)/2+hw(1));
cols = round(sz(2)/2-hw(2)):round(sz(2)/2+hw(2));
rows = min(max(rows,1),sz(1));
cols = min(max(cols,1),sz(1));
% assign a value to the ROI
inpict(rows,cols,:) = newcolor;
imshow(inpict)
Note that this isn't going to be pixel-perfect depending on whether your image/rectangle have odd/even geometry. If you need something to be perfect, you'll have to decide where to make the necessary compromises.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!