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

2 ビュー (過去 30 日間)
John Smith
John Smith 2018 年 3 月 8 日
回答済み: Naga 2024 年 11 月 26 日
myimage=imread('someimage.jpn') selectedpixels = imcrop(myimage)
filtering "myimage" with the "selectedpixels" to only show this the selected pixels.

回答 (1 件)

Naga
Naga 2024 年 11 月 26 日
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);

Community Treasure Hunt

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

Start Hunting!

Translated by