Backgroud Added to images after imwrap transformations
Show older comments
I am performing simple transformations but the Matlab adds backgroud to the image to make it Rectangle. The image has transparent backgroud. I know how to read the image and remove background but I fail to remove it after the transformations
I=imread('d.png');
I=flipud(I);
T = [1 0
1 1];
figure;
T(3,3)=1;
[Iw,R]=imwarp(I, affine2d(T'));
h=imshow(Iw);
axis on xy;
set(h,'XData',R.XWorldLimits,'YData',R.YWorldLimits);
set(gca,'XLim',R.XWorldLimits,'YLim',R.YWorldLimits);
The following is being used

After the transformation the below image is displayed

I do not want this background to appear
Accepted Answer
More Answers (1)
Here is the complete code (your diamond image was used with DIAM.png name):
I=imread('DIAM.png');
I=flipud(I);
T = [1 0
1 1];
figure
imshow(I)
title('Original')
figure;
T(3,3)=1;
[Iw,R]=imwarp(I, affine2d(T'));
% Convert the Image to Grayscale:
Gray_img = rgb2gray(Iw);
% Create a Mask (called B_mask) for the Background Color:
B_mask = Gray_img ==0; % Adjust the threshold based on the transformed image
% Apply the mask (B_mask) to remove the background color
Final_img = Iw;
Final_img(repmat(B_mask, [1, 1, 3])) = 255; % Set background pixels to white
h=imshow(Final_img);
axis on xy;
set(h,'XData',R.XWorldLimits,'YData',R.YWorldLimits);
set(gca,'XLim',R.XWorldLimits,'YLim',R.YWorldLimits);
title('Transformed Image')
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


