应用滤镜-applyFilter

  destBmp.applyFilter(sourceBitmapData, sourceRect, destPoint, filter);
·sourceBitmapData -- 要使用的输入位图图像。源图像可以是另一个BitmapData对象,也可以引用当前
BitmapData实例
·sourceRect -- 定义要用作输入的源图像区域的矩形
·destPoint -- 目标图像(当前BitmapData实例)中与源矩形的左上角对应的点
·filter -- 用于执行过滤操作的滤镜对象

如果 BitmapData 对象和指定为 sourceBitmapData 参数的对象是同一对象,应用程序将使用该对象的临时副本来执行滤镜。为了获得最佳性能,请避免这种情况可以直接定义Bitmap.filters属性,它不会直接接触BitmapData的像素数据,因为滤镜只应用在包装BitmapData的Bitmap上

package {   
    import flash.display.Bitmap;   
    import flash.display.BitmapData;   
    import flash.display.Sprite;   
    import flash.events.Event;   
    import flash.filters.BlurFilter;   
    import flash.geom.Point;   
  
    public class Sample0319 extends Sprite   
    {   
        private var image:Bitmap;   
        private var blurFilter:BlurFilter;   
        private var point:Point;   
           
        public function Sample0319()   
        {   
            image = new Bitmap();   
            image.bitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0x000000);   
            this.addChild(image);   
               
            blurFilter = new BlurFilter();   
            point = new Point();   
               
            this.addEventListener(Event.ENTER_FRAME,onEnterFrame);   
        }   
           
        private function onEnterFrame(target:Event):void   
        {   
            for(var i:uint=0;i<100;i++)   
            {   
                image.bitmapData.setPixel(mouseX + Math.random()*20 - 10,   
                              mouseY + Math.random()*20 - 10,   
                              0xFFFFFF);       
            }   
            image.bitmapData.applyFilter(image.bitmapData,image.bitmapData.rect,point,blurFilter);   
        }   
    }   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用MATLAB中的Image Processing Toolbox和Graphical User Interface (GUI)实现对鼠标选中的图像区域进行滤镜处理。以下是一些实现步骤: 1. 创建一个GUI,包含一个用于显示图像的axes对象和一个用于选择滤镜类型的popupmenu对象。 2. 用imread函数加载图像并在axes对象中显示。 3. 使用imrect函数创建一个可调整大小和位置的矩形框,用于选择图像区域。可以使用addNewPositionCallback函数监听矩形框的位置变化并更新选择的图像区域。 4. 当用户选择滤镜类型并点击“应用”按钮时,使用用户选择的滤镜对选择的图像区域进行处理。可以使用imfilter函数实现不同类型的滤镜,如高斯滤波、中值滤波等。 5. 在axes对象中更新处理后的图像。 下面是一个示例代码,演示如何实现对鼠标选中的图像区域进行高斯滤波处理: ```matlab function myFilterGUI % 创建GUI fig = figure('Position',[200,200,500,500]); ax = axes('Units','normalized','Position',[0.1,0.2,0.8,0.7]); popup = uicontrol('Style','popupmenu','String',{'高斯滤波','中值滤波'},... 'Units','normalized','Position',[0.1,0.1,0.2,0.05]); button = uicontrol('Style','pushbutton','String','应用','Units',... 'normalized','Position',[0.4,0.1,0.1,0.05],'Callback',@applyFilter); % 加载图像 img = imread('peppers.png'); imshow(img,'Parent',ax); % 创建矩形框 h = imrect(ax,[100,100,100,100]); addNewPositionCallback(h,@(p) updateRect(p,img)); % 更新图像区域 rect_pos = getPosition(h); rect_img = img(rect_pos(2):rect_pos(2)+rect_pos(4),rect_pos(1):rect_pos(1)+rect_pos(3),:); % 更新矩形框位置 function updateRect(pos,img) rect_img = img(pos(2):pos(2)+pos(4),pos(1):pos(1)+pos(3),:); end % 应用滤镜 function applyFilter(~,~) filter_type = popup.String{popup.Value}; if strcmp(filter_type,'高斯滤波') h_filter = fspecial('gaussian',[3 3],0.5); elseif strcmp(filter_type,'中值滤波') h_filter = ones(3,3)/9; end filtered_img = imfilter(rect_img,h_filter); imshow(filtered_img,'Parent',ax); end end ``` 在GUI中选择不同的滤镜类型和不同的图像区域,点击“应用”按钮即可看到滤镜处理后的图像。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值