イメージがありますが、
.
私はこれをやりたかった:
いくつかの操作を行った後、画像を再結合して最終結果を得ることができるはずです。私のコードはこれです:
clc;
clear all;
close all;
tic
I = imread('ChanVese.jpg');
I = imresize(I, [128 128]);
Img = I;
I = double(I(:, :, 1));
figure();
imshow(Img);
% // As there are three figures
crop_pos = zeros(3, 4);
new_image = zeros(size(I));
c = cell(1, 3);
for i=1:3
% // Sub-divide the image
h = imrect(gca);
% // To make the rect function bounded within the image size
addNewPositionCallback(h, @(p) title(mat2str(p, 3)));
fcn = makeConstrainToRectFcn('imrect', get(gca, 'XLim'), get(gca, 'YLim'));
setPositionConstraintFcn(h, fcn);
crop_area = wait(h)
crop_pos(i, :) = (crop_area);
% // Cropped is the new cropped image on which we will do our operation
cropped = (imcrop(Img, crop_area));
c{i} = cropped;
% // Do operation on the image
%***************************
% Code to be written
%***************************
% // Insert the part-image back into the image
new_image(crop_pos(i, 2):crop_pos(i, 4), crop_pos(i,1):crop_pos(i, 3)) = c{i};
end
imagesc(new_image, [0 255]),colormap(gray);axis on
toc
私の問題は imrect 関数にあります。例を挙げてみます。サイズが [128x128] の画像全体を選択しても、crop_pos の出力は次のようになります。
[x,y,w,h] = [0.5, 0.5, 128, 128]
一方、実際にはそうあるべきです
[x, y, w, h] = [1, 1, 128, 128];
また、幅と高さが浮動小数点で指定されることもあります。これはなぜですか?MATLAB は画像を行列として扱い、そうすることでそれらを個別のコンポーネントに変換すると思います。したがって、すべての値は整数でなければなりません。
どうすればこの問題を解決できますか?