hi i need to divide image into 64x64 and in each block find maximum pixel intensity value,and change all other pixel value to this maximum value.

4 次查看(过去 30 天)
please provide matlab code
  2 个评论
Jan
Jan 2015-8-14
What have you tried so far and which problems occur? Do you have the image processing toolbox or do you want to write the required 6 lines of code by your own? Is the size of the image a multiple of 64 and if not, how do you want to handle the edges?
kaavya subramani
kaavya subramani 2015-8-14
From the final result of the curvelet transform i need to extract distinct object,so i thought of this idea.my image size is 192x192.from this i need to find contours.my image is
|

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2015-8-14
Using SEPBLOCKFUN ( Download ),
MaxVals=sepblockfun(yourImage,[64,64], @(B,d) max(B,[],d) );
result=kron(MaxVals,ones(64));
  3 个评论
Walter Roberson
Walter Roberson 2015-8-15
It would be interesting to test
block_max = @(blockstruct) max(blockstruct.data(:));
Maxed_Image = blockproc(yourImage, [64,64], block_max);
result = kron(Maxed_Image, ones(64));
One item to note is that the kron version will have an output that is always a multiple of 64 in height and width, whereas the blockproc version will have an output that is the same size as the original. blockproc submits partial blocks when the original is not a multiple of the requested block size, and I designed the set_to_max to accept partial blocks -- that is why I passed the size of the block to ones() instead of assuming 64 x 64.
Matt J
Matt J 2015-8-15
Yes, my solution definitely doesn't handle partial blocks. As for block_max, here's how it does on my machine,
yourImage=rand(12800);
block_max = @(blockstruct) max(blockstruct.data(:));
tic
version1 = blockproc(yourImage, [64,64], block_max);
toc
%Elapsed time is 1.962054 seconds.
tic
version2=sepblockfun(yourImage,[64,64], @(B,d) max(B,[],d) );
toc
%Elapsed time is 0.128351 seconds.

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2015-8-14
set_to_max = @(blockstruct) ones(size(blockstruct.data),class(blockstruct.data)) * max(blockstruct.data(:));
grainsize = 64; %if you want the new boxes to be 64 x 64
Maxed_Image = blockproc(ExistingImage, grainsize, set_to_max);

Image Analyst
Image Analyst 2015-8-15
blockproc() will do that but normally moves over in "jumps" of the block size (64 pixels in your case). So the output image will be 1/64th the size of the original, unless you take special care (like Walter did) to make the outputs 64x64 blocks instead of just a single number (the max in the block). By the way, to get his code to work, make this change:
grainsize = [64, 64]; %if you want the new boxes to be 64 x 64
If you want the block to move over one pixel at a time, you can use imdilate(), which is a local max filter. Run this code to compare the results to see which one you want.
% Startup code.
clc; % Clear command window.
workspace; % Make sure the workspace panel with all the variables is showing.
format long g;
format compact;
fontSize = 20;
ExistingImage = imread('cameraman.tif');
subplot(3,1,1);
imshow(ExistingImage);
axis on
title('Original image', 'FontSize', fontSize);
set_to_max = @(blockstruct) ones(size(blockstruct.data),class(blockstruct.data)) * max(blockstruct.data(:));
grainsize = [64, 64]; %if you want the new boxes to be 64 x 64
Maxed_Image = blockproc(ExistingImage, grainsize, set_to_max);
subplot(3,1,2);
imshow(Maxed_Image);
axis on
title('Blockproc image (block shifts by 64 pixels)', 'FontSize', fontSize);
dilatedImage = imdilate(ExistingImage, true(64,64));
subplot(3,1,3);
imshow(dilatedImage);
axis on
title('Dilated image (block shifts by 1 pixel)', 'FontSize', fontSize);

Community Treasure Hunt

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

Start Hunting!

Translated by