From: Oleg Komarov on 20 Feb 2010 05:31 I never use matlab graphics (apart from simple plots) and I decided I should give it a try. I need some indications on the steps to follow and which functions to use (I don't need detailed info) Lets say I have a barplot and I want to fill each bar with a .png image (37 by 32 pixels) how can I proceed? Thanks in advance Oleg
From: Oleg Komarov on 22 Feb 2010 16:44 I learned something in the meantime. It's not possible to do that since a barplot is made of patches. I have to recreate the barplot with surfaces... While I'm trying to figure it out myself, any hint is really welcome. Oleg
From: ImageAnalyst on 22 Feb 2010 20:07 Oleg Komarov: Here's a way to replace all the bars with an image, like the bars were a mask on the image. I suppose you could adapt it if you wanted the entire image in each bar singly. You seem like a smart guy so I didn't comment it as much as I'd normally do - I expect you'll get the idea and figure it out. Be sure to fix any lines broken into two by the newsreader. % Demo to replace bars in a bar chart with an image. % by ImageAnalyst clc; close all; clear all; workspace; % Display workspace panel. % set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. % Generate some sample data in the range 0-9. a= uint8(10 * rand(8,1)) hFig = figure; hBars = bar(a); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. structFrame = getframe(hFig); screenshot = structFrame.cdata [chartRows chartCols numberOfChartColorPlanes] = size(screenshot); redPlane = screenshot(:, :, 1); greenPlane = screenshot(:, :, 2); bluePlane = screenshot(:, :, 3); figure; imshow(screenshot); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. figure; subplot(1,3,1); imshow(redPlane); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. subplot(1,3,2); imshow(greenPlane); subplot(1,3,3); imshow(bluePlane); % Read in standard MATLAB demo image. grayImage = imread('cameraman.tif'); [imageRows imageCols numberOfColorPlanes] = size(grayImage); % Resize it to match the bar chart. grayImage = imresize(grayImage, [chartRows chartCols], 'nearest'); figure; imshow(grayImage, []); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. title('Original Grayscale Image'); % Specify the color of the bars % I looked at redPlane, etc. in the variable editor to determine these. barColorR = 0; barColorG = 0; barColorB = 143; barMask = (redPlane == barColorR) & (greenPlane == barColorG) & (bluePlane == barColorB); maskedImage2 = grayImage .* uint8(barMask); barRegions = (maskedImage2 > 0); redPlane(barRegions) = maskedImage2(barRegions); greenPlane(barRegions) = maskedImage2(barRegions); bluePlane(barRegions) = maskedImage2(barRegions); maskedImage = cat(3, redPlane, greenPlane, bluePlane); figure; imshow(maskedImage, []); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
From: Oleg Komarov on 24 Feb 2010 06:34 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <143ade5d-12d5-44bd-a979-098a4c1592a1(a)h17g2000vbd.googlegroups.com>... > Oleg Komarov: > Here's a way to replace all the bars with an image, like the bars were > a mask on the image. I suppose you could adapt it if you wanted the > entire image in each bar singly. > > You seem like a smart guy so I didn't comment it as much as I'd > normally do - I expect you'll get the idea and figure it out. Be sure > to fix any lines broken into two by the newsreader. > > % Demo to replace bars in a bar chart with an image. > % by ImageAnalyst > clc; > close all; > clear all; > workspace; % Display workspace panel. > % set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > % Generate some sample data in the range 0-9. > a= uint8(10 * rand(8,1)) > hFig = figure; > hBars = bar(a); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > structFrame = getframe(hFig); > screenshot = structFrame.cdata > [chartRows chartCols numberOfChartColorPlanes] = size(screenshot); > redPlane = screenshot(:, :, 1); > greenPlane = screenshot(:, :, 2); > bluePlane = screenshot(:, :, 3); > figure; > imshow(screenshot); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > figure; > subplot(1,3,1); > imshow(redPlane); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > subplot(1,3,2); > imshow(greenPlane); > subplot(1,3,3); > imshow(bluePlane); > > % Read in standard MATLAB demo image. > grayImage = imread('cameraman.tif'); > [imageRows imageCols numberOfColorPlanes] = size(grayImage); > % Resize it to match the bar chart. > grayImage = imresize(grayImage, [chartRows chartCols], 'nearest'); > figure; > imshow(grayImage, []); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > title('Original Grayscale Image'); > > % Specify the color of the bars > % I looked at redPlane, etc. in the variable editor to determine > these. > barColorR = 0; > barColorG = 0; > barColorB = 143; > > barMask = (redPlane == barColorR) & (greenPlane == barColorG) & > (bluePlane == barColorB); > maskedImage2 = grayImage .* uint8(barMask); > barRegions = (maskedImage2 > 0); > redPlane(barRegions) = maskedImage2(barRegions); > greenPlane(barRegions) = maskedImage2(barRegions); > bluePlane(barRegions) = maskedImage2(barRegions); > maskedImage = cat(3, redPlane, greenPlane, bluePlane); > figure; > imshow(maskedImage, []); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. I don't have the IPT, but I get the concept. If no workaround is possible without the IPT I will consider buying it. Oleg
From: ImageAnalyst on 24 Feb 2010 08:09 Nothing in there really requires that you have the Image Processing Toolbox. I used imshow() only for the demo - you wouldn't use it, you'd just use whatever method you're currently using to display/plot figures. And for imresize() that's just to get the matrices the same size. You could replace that either by just padding out the array, or using interp2() or some other method.
|
Next
|
Last
Pages: 1 2 Prev: re-arranging data into a matrix Next: out of memory, memory problem in large matrix |