Filter löschen
Filter löschen

How to create a white mask?

2 Ansichten (letzte 30 Tage)
Jessica
Jessica am 10 Mär. 2018
Kommentiert: Jessica am 10 Mär. 2018
I am using the below code to overlay a black, elliptical mask around an imported photo. Rather than having the imported photo surrounded by black, is there a way to change the black background color to white?
I = imread (ConvertFileName);
%# Create an ellipse shaped mask c = fix(size(I) / 2); %# Ellipse center point (y, x) r_sq = [76, 100] .^ 2; %# Ellipse radii squared (y-axis, x-axis) [X, Y] = meshgrid(1:size(I, 2), 1:size(I, 1)); ellipse_mask = (r_sq(2) * (X - c(2)) .^ 2 + r_sq(1) * (Y - c(1)) .^ 2 <= prod(r_sq));
%# Apply the mask to the image I_cropped = bsxfun(@times, I, uint8(ellipse_mask)); imshow(I_cropped)

Antworten (1)

Image Analyst
Image Analyst am 10 Mär. 2018
See my attached demo.
  1 Kommentar
Jessica
Jessica am 10 Mär. 2018
Thanks for uploading this. When I run the script, the background is still black. Is there a way to modify my code to just reverse the colors? The other issue is that I want to save the image with the same quality as the original image. I've been doing that with the code I pasted above with:
Filename=ConvertFileName; export_fig TempFigure.jpg -r300; B=imread('TempFigure.jpg');imwritesize(B, Filename, 2.14, 300); %Save file with 2.14 inch width and 300 dpi delete('TempFigure.jpg'); close all;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by