matlab - Paste Cropped image without changing color -


i trying add more elements image merging cropped image. code works fine cropped image upon merging doesn't retain color.

b = a(y1:y2,x1:x2); subplot(2, 2, 3); imshow(b); axis on; [rows2, columns2] = size(b); promptmessage = sprintf('click on upper left point want paste it,\nor click cancel quit.'); titlebarcaption = 'continue?'; [x, y] = ginput(1); r1 = int32(y); c1 = int32(x); r2 = r1 + rows2 - 1; r2 = min([r2 rows]); c2 = c1 + columns2 - 1; c2 = min([c2, columns]); plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-'); a(r1:r2, c1:c2) = b(1:(r2-r1+1), 1:(c2-c1+1)); subplot(2, 2, 4); imshow(a); 

the final image has cropped image color of cropped image changes.please let me know how retain color of cropped image.

thanks.

it doesn't retain colour because extracting out first channel of image. i'm assuming images rgb images, , need extract channels @ same spatial coordinates. therefore, need slice third dimension well:

b = a(y1:y2,x1:x2,:); %// change subplot(2, 2, 3); imshow(b);  % imange b cropped image same color  plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-'); a(r1:r2, c1:c2,:) = b(1:(r2-r1+1), 1:(c2-c1+1),:); %// change subplot(2, 2, 4); imshow(a); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -