MATLAB: Extracting pixels from an image random extractimage processingMATLAB Hello, How can I extract 100 pixels color randomly from an image ? Best Answer One way:row = randi(size(yourimage, 1), 100, 1); %select 100 row coordinates at randomcol = randi(size(yourimage, 1), 100, 1); %and 100 columns to go with itrgb = yourimage(sub2ind(size(yourimage), repmat(row, 1, 3), repmat(col, 1, 3), repmat(1:3, 100, 1))); %for pretty displaytable(row, col, rgb) Related SolutionsMATLAB: How to change the color of pixels in a binary image See attached m-file. MATLAB: Problem displaying a satellite image That's not a gray scale image you attached, it's an RGB image. So try thisrgbImage = imread('C1fig.jpg');whos rgbImagesubplot(2, 1, 1);imshow(rgbImage);title('Original RGB image C1fig.jpg');axis('on', 'image');impixelinfomask = rgbImage(:, :, 1) == 0;% Extract the individual red, green, and blue color channels.redChannel = rgbImage(:, :, 1);greenChannel = rgbImage(:, :, 2);blueChannel = rgbImage(:, :, 3);redChannel(mask) = 255;greenChannel(mask) = 0;blueChannel(mask) = 0;% Recombine separate color channels into a single, true color RGB image.rgbImage = cat(3, redChannel, greenChannel, blueChannel);subplot(2, 1, 2);imshow(rgbImage);axis('on', 'image');impixelinfotitle('Altered RGB image');If it really is a gray scale image, you can try this:grayImage = imread('C1fig.jpg');if ndims(grayImage) == 3; grayImage = rgb2gray(grayImage);endwhos grayImagesubplot(2, 1, 1);imshow(grayImage);title('Original image C1fig.jpg');axis('on', 'image');impixelinfomask = grayImage == 0;% Initialize the individual red, green, and blue color channels.redChannel = grayImage;greenChannel = grayImage;blueChannel = grayImage;redChannel(mask) = 255;greenChannel(mask) = 0;blueChannel(mask) = 0;% Recombine separate color channels into a single, true color RGB image.rgbImage = cat(3, redChannel, greenChannel, blueChannel);subplot(2, 1, 2);imshow(rgbImage);axis('on', 'image');impixelinfotitle('Altered RGB image'); Related QuestionRead three different RGB band and Swap the BandImage processing structural Tensor EquationExtracting black pixels from a specific region of an image and overlaying it on another imageConvertion rgb image blue channel imageHow to make backgound of image blackWhat is an R-B feature image,how to convert an RGB image to R-B feature image? ,plase give code in matlab
Best Answer