フィルターのクリア

how to scramble pixels of specific part of image

4 ビュー (過去 30 日間)
Jessica
Jessica 2018 年 6 月 4 日
回答済み: DGM 2024 年 7 月 2 日 17:45
Can anyone suggest a way to scramble all the pixels within a circle of an image?
I am using this code to scramble all the pixels within an image:
img=imread(SpecificStimuli);
rmig=reshape(img,[],size(img,3));
n=size(rmig,1);
simg=rmig(randperm(n),:);
simg=reshape(simg,size(img));
imwrite(simg, OutputName);
But, rather than scrambling all the pixels I would like to only scramble the pixels within this oval of the original image:
Radius=608; Centered at: Center Row=676 Center Column=642

回答 (1 件)

DGM
DGM 2024 年 7 月 2 日 17:45
Consider the example:
% an image
inpict = imread('peppers.png');
% generate a mask using any appropriate method
% see also imellipse(), drawellipse()
sz = size(inpict,1:3);
points = makeoval(75,[180 250],-135); % attached
mask = poly2mask(points(:,1),points(:,2),sz(1),sz(2));
mask = repmat(mask,[1 1 sz(3)]); % expand the mask
% get the masked pixels as a Mx3 color table, shuffle it
extractedCT = reshape(inpict(mask),[],sz(3));
extractedCT = extractedCT(randperm(size(extractedCT,1)),:);
% compose the output image
outpict = inpict;
outpict(mask) = extractedCT;
% show it
imshow(outpict)
Might want to be specific when you say "oval'. Someone might guess that you mean "strictly an ellipse", but I don't think many people would think you actually meant "circle".

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by