简体   繁体   中英

How can I make a synthetic image in MATLAB?

I am using MATLAB 2015b to make a synthetic image as following (without green circle)

在此处输入图片说明

It maybe hard to make the star image for me. Hence, I used a simple shape as square as below code. However, I cannot create similar intensity as example image. If it is possible, would you help me to make the image? I think that the image has two components: intensity following Gaussian distribution and inhomogeneous intensity. Thank all

%% Gray image
rows = 256;
columns = 256;
grayImage = ones(rows, columns, 'uint8').*200;
xCoords= [80 180 180 80 80];
yCoords = [80 80 180 180 80];
mask = poly2mask(xCoords, yCoords, rows, columns);
grayImage(mask) = 80; 
%% First component Gray+noise
im_normal=double(grayImage./max(grayImage(:)));
im_noise= imnoise(im_normal,'gaussian',0,0.02);
%% Second component: Inhomogeneous term
X = 1:rows;                           % X is a vector from 1 to imageSize
X0 = (X / rows) -0.2;                 % rescale X 
Xm = meshgrid(X0, X0);             % 2D matrices
%% Output image
Out_Img=im_noise.*Xm;
subplot(121);imshow(grayImage);
subplot(122);imshow(Out_Img,[]);

This is my current result

在此处输入图片说明

I would try the following approach:

  1. Find an approximation for the homogeneity field of the star image using gaussian blur:

    homogeneity = imfilter(I,fspecial('disk',15),'replicate');

  2. subtract the homogeneity field from the input image.

  3. Segment the star shape manually

  4. Calculate the histogram of the star using imhist function and the segmentation mask from previous stage. Divide it by the sum of the histogram. Thus you will get the probability vector which represents the star.

  5. do the same thing with the background - calculate the probability vector which represents the background.

  6. when generating the output:

    a. for each pixel inside of the square, generate a grayscale value randomly, using the probability vector from stage 2.

    b. for each background pixel, generate a grayscale value randomly using the probability vector from stage 3.

    c. finally - add the homogeneity field from stage 1 to your result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM