Local Contrast by dragging rectangle on an image
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Muhammad Abir
 el 22 de Dic. de 2020
  
    
    
    
    
    Respondida: Hrishikesh Borate
    
 el 31 de Dic. de 2020
            Hello, 
I am trying to develop a code that can allow user to draw a rectangle or arbitrary size. Then when the user drags the rectangle, it will enhance the contrast of the region inside the rectangular area only. I tried to use drawrectangle and addlistener but it looks like it not working as I want. In my code, when I display the image, the contrast enhanced aera is cropped and displayed in the upper corner of the image, but my plan is that the the contrast enhanced image will be displayed on top of the origianal image at the location the rectangle is selected. Here is my code so far: 
imshow('cameraman.tif');     
roi = drawrectangle('LineWidth',2,'Color','red');
addlistener(roi,'MovingROI',@(r1,evt) allevents(Img, r1,evt));
function allevents(Img, src,evt)
       evname = evt.EventName;
       roi= round(evt.CurrentPosition); 
           switch(evname)
              case{'MovingROI'}
                  CroppedImage= imcrop(Img,roi); 
           end 
0 comentarios
Respuesta aceptada
  Hrishikesh Borate
    
 el 31 de Dic. de 2020
        Hi, 
I understand that you want to define a dynamic rectangular region of interest and enhance the contrast of the region inside the rectangular area only. 
For contrast enhancement, several techniques can be used, as shown here. In the following code, imadjust is used. 
I = imread('cameraman.tif');
himg = imshow(I); 
roi = drawrectangle('LineWidth',2,'Color','red');
addlistener(roi,'MovingROI',@(src,evt)allevents(I, himg, src, evt));
function allevents(Img, himg, src,evt)
    evname = evt.EventName;
    switch(evname)
        case{'MovingROI'}
            rectPos = evt.CurrentPosition();
            croppedImage = imcrop(Img, rectPos);
            enhancedImage = imadjust(croppedImage);
            newImg = Img;
            newImg(rectPos(2)+(0:rectPos(4)), rectPos(1)+(0:rectPos(3))) = enhancedImage;
            himg.CData = newImg;
    end
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

