how can i show only the selected pixels within an image.

myimage=imread('someimage.jpn') selectedpixels = imcrop(myimage)
filtering "myimage" with the "selectedpixels" to only show this the selected pixels.

Answers (1)

Hi John,
To display only the selected pixels from an image using MATLAB, you can use logical indexing to create a mask of the selected region and then apply this mask to the original image. Here's how you can do it
% Load the image
myimage = imread('anyimage.jpg');
% Select the region of interest (ROI)
[selectedpixels, rect] = imcrop(myimage);
% Create a mask of the same size as the image
mask = false(size(myimage, 1), size(myimage, 2));
x = round(rect(1));
y = round(rect(2));
width = round(rect(3));
height = round(rect(4));
% Set the ROI in the mask to true
mask(y:(y+height), x:(x+width)) = true;
% Apply the mask to the image
filteredimage = myimage;
filteredimage(repmat(~mask, [1 1 size(myimage, 3)])) = 0;
% Display the filtered image
imshow(filteredimage);

Asked:

on 8 Mar 2018

Answered:

on 26 Nov 2024

Community Treasure Hunt

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

Start Hunting!