フィルターのクリア

Save an image with a plot

1 回表示 (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2020 年 4 月 9 日
コメント済み: Ameer Hamza 2020 年 4 月 9 日
Hey, see if anyone can fix a problem I have. I add an example using the sample image 'cameraman.tif', the image of the real code is another one but to get an idea it works perfectly.
I need to highlight the detected outline, so what I came up with was to get the pixel coordinates and represent them on top of the image by saying that these points are thicker.
Also, I make a crop of the image and I need to show in the original image the crop rectangle used.
When I save it, I want the highlighted pixels to look white and the square to look any other color, for example red.
Do you have any ideas on how to make the image as tight as possible so that the white pixels look white and not black?
Translated with www.DeepL.com/Translator (free version)
I = imread('cameraman.tif');
BW = edge(I,'canny');
[J,rect2] = imcrop(BW);
[r,c] = find ( BW == 1 );
pP = [c r];
f = figure;
imshow(I)
hold on
plot(pP(:,1),pP(:,2),'.w','MarkerSize',5)
rectangle('Position',rect2,'EdgeColor','red','LineWidth',3)
print('TH.tif','-dtiff')
What i want to obtain
What I want to have
What i obtain using print.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 9 日
Try this
I = imread('cameraman.tif');
BW = edge(I,'canny');
[J,rect2] = imcrop(BW);
[r,c] = find ( BW == 1 );
pP = [c r];
f = figure;
ax = axes;
imshow(I)
hold on
plot(pP(:,1),pP(:,2),'.w','MarkerSize',5)
rectangle('Position',rect2,'EdgeColor','red','LineWidth',3)
frame = getframe(gca);
imwrite(frame.cdata, 'TH.tif')
If you are using R2020a, then MATLAB also introduced exportgraphics
I = imread('cameraman.tif');
BW = edge(I,'canny');
[J,rect2] = imcrop(BW);
[r,c] = find ( BW == 1 );
pP = [c r];
f = figure;
ax = axes;
imshow(I)
hold on
plot(pP(:,1),pP(:,2),'.w','MarkerSize',5)
rectangle('Position',rect2,'EdgeColor','red','LineWidth',3)
exportgraphics(gca,'TH.tif')
  2 件のコメント
Alejandro Fernández
Alejandro Fernández 2020 年 4 月 9 日
Both works! Thank you so so much!!
Ameer Hamza
Ameer Hamza 2020 年 4 月 9 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by