create a new image in matlab

To create a new image in Matlab, you can use the imread function to read an existing image. Alternatively, you can use one of the built-in functions to create a new image from scratch. Here's an example of creating a blank black and white image with size 256x256:

main.m
img = zeros(256,256);
imshow(img);
35 chars
3 lines

This will create a new image with all pixels set to 0. To set individual pixels to particular values, you can use indexing:

main.m
img(50,50) = 255; %set a single pixel to white
img(100:150, 100:150) = 128; %set a square region to gray
105 chars
3 lines

You can also create a new image with a specific color using the repmat function to repeat a single pixel:

main.m
red = uint8([255, 0, 0]); %define a red pixel as [R,G,B]
img = repmat(red, [256, 256, 1]); %create a 256x256 image of red pixels
imshow(img);
142 chars
4 lines

Here, we've used the uint8 function to create a value for our red pixel, then repeated it using repmat to create a new image. The third argument [1] specifies that we want to repeat the pixel along the third dimension, which corresponds to the color channels (red, green, blue).

related categories

gistlibby LogSnag