How can I remove the background fro the image and display roi for the shape of the image left ?

1 回表示 (過去 30 日間)
Pallavi Rawat
Pallavi Rawat 2022 年 1 月 6 日
回答済み: DGM 2022 年 1 月 7 日
How can I remove the white background from the image and have the hammer be displayed with ROI of its shape by just ONE CLICK and could be dragged and dropped anywhere on the screen?

回答 (1 件)

DGM
DGM 2022 年 1 月 7 日
This probably isn't what you want, but it's probably a component of what you want.
To do image processing operations with a simple mouse interface implies the construction of a GUI. That's an involved task that would require specific requirements to be established. I'm going to ignore that for now.
If you want the hammer to be displayed as a transparent object over other windows like this:
... then as far as I know, you're out of luck. The graphics tools don't work like that. You might be able to use some external program to display it, but I wouldn't know.
Let's back up for a minute though. What can be done? The hammer can be separated from the background and composed with another image.
FG = imread('TO.jpg');
BG = imread('hammerbg.jpg'); % nevermind where this image came from
% create a mask
mask = repmat(~all(FG>=254,3),[1 1 3]);
% apply the mask
BG(mask) = FG(mask);
imshow(BG)
However, there isn't really a way to display the hammer alone. Tools like imshow() don't support RGBA arrays or anything. There are tools in MIMT that support RGBA, but all that's going to do is show the hammer over a checkerboard background.
You could maybe export the image as a PNG with transparency and use some other tool to do the work?
imwrite(FG,'hammer.png','alpha',double(mask(:,:,1)));
It's hard to tell because the webpage background is white, but that's a transparent PNG.

Community Treasure Hunt

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

Start Hunting!

Translated by